150 likes | 422 Views
Binary Numbers. Bit patterns. Bits can be used to represent patterns Specifically, any system or set of symbols can be translated into bit patterns patterns of ones and zeros 10100001101 Example: characters from any language alphabet
E N D
Bit patterns • Bits can be used to represent patterns • Specifically, any system or set of symbols can be translated into bit patterns • patterns of ones and zeros • 10100001101 • Example: characters from any language alphabet • Require enough bits so that all symbols have a unique bit pattern to represent them • How many bits are needed to represent the English alphabet? • Require set of symbols is finite
How many bits? • A bit pattern consisting of a single bit can represent at most two symbols • possible patterns are 0 and 1 • A bit pattern consisting of two bits can represent at most four symbols • possible patterns are 00, 01, 10 and 11 • In general, a bit pattern consisting of n bits can represent at most 2n symbols • How many bits are needed to represent the English alphabet? • we can represent 26 symbols using 5 bits (25=32) • 4 bits is not enough (24=16)
Decimal (base 10) representation • We commonly represent numbers in decimal (base 10) • Numbers are represented using patterns of thedigits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } • Position of each digit represents a power of ten • Example: Consider the decimal representation 2307 2 3 0 7 position: 3 2 1 0 2307 = 2103 + 3102 + 0101 + 7100
Base n representation • A base n system contains n distinct symbols, the digits 0 through n -1 • Numeric values greater than n -1 are represented by a pattern of the n symbols • The value of any symbol in the string is found by multiplying that symbol by np, where p is the distance from the rightmost symbol in the pattern • Computers represent information using bit patterns, or binary (base 2) representation • Numbers represented in base 2 are usually called binary numbers
Binary (base 2) representation • The binary representation contains two symbols: { 0, 1 } • Position of each symbol represents a power of two • What is the value of the binary representation 111? 1 1 1 position: 2 1 0 111= 122 + 121 + 120 = 14+ 12 + 11 = 4 + 2 + 1 = 7
Binary representation • What is the value of the binary representation 1010? 1 0 1 0 position: 3 2 1 0 1010= 123+ 022 + 121 + 020 = 18 + 04+ 12 + 01 = 8 + 0 + 2 + 0 = 10
Binary addition 0 + 0 ------- 0 1 + 0 ------- 1 0 + 1 ------- 1 1 + 1 ------- 10 • Represent sum of binary numbers as a binary number decimal addition binary addition 1+1 = 2 1+1 = 10 1+1+1 = 3 1+1+1 = 10+1 = 11
Adding binary numbers 1 1 carry 101 + 11 ----------- 1000 1 1 carry 111 + 110 ----------- 1101 101 + 10 --------- 111 1 1 1 carry 10101010111 + 110000110 ------------------------ 11011011101
Converting decimal to binary Decimal conversion Binary 0 = 020= 0 1 = 120= 1 2 = 121 + 020 = 10 3 = 121 + 120= 11 4 = 122 + 021 + 020= 100 5 = 122 + 021 + 120 = 101 6 = 122 + 121 + 020= 110 7 = 122 + 121 + 120 = 111 8 = 123 + 022 + 021 + 020 = 1000
Converting decimal to binary remainder 1 • Repeated division by two until the quotient is zero • What is the binary representation of 30? remainder 1 remainder 1 remainder 1 remainder 0 11110
Converting decimal to binary remainder 1 • Repeated division by two until the quotient is zero • What is the binary representation of 47? remainder 0 remainder 1 remainder 1 remainder 1 remainder 1 111001
Problems • Convert 1011000 to decimal representation • Add the binary numbers 1011001 and 10101 and express their sum in binary representation • Convert 77 to binary representation
Solutions • Convert 1011000 to decimal representation 1011000 = 126 + 025 + 124 + 123 + 022 + 021 + 020= 64+ 16+ 8= 88 • Add the binary numbers 1011001 and 10101 and express their sum in binary representation • Convert 77 to binary representation: 1001101 1011001 + 10101 ---------------- 1101110
Ternary (base 3) representation • Numbers are represented using the symbols { 0, 1, 2 } • Convert the ternary representation 1021 to decimal 1021 = 133 + 032 + 231 + 130= 27 + 0 + 6 + 1 = 34 • Convert the ternary representation 2001 to decimal2001 = 233 + 032 + 031 + 130= 54 + 0 + 0 + 1 = 55 • Add the ternary numbers 1021 and 2001 and express their sum in ternary representation • Convert 77 to ternary representation