Download presentation
Presentation is loading. Please wait.
Published byEric Thomas Modified over 8 years ago
1
CPE 201 Digital Design Lecture 2: Digital Systems & Binary Numbers (2)
2
2 Lecture Outline Number representations Conversions between bases
3
3 Number Base Representations Positional Number Systems –Traditional way to represent numbers Number represented as –String of digits –Each digit position has an associated weight Base r system –Coefficients are multiplied by powers of r a n a n-1 … a 0.a -1 a -2 … a -m = r n a n + r n-1 a n-1 + …+ r 2 a 2 + r 1 a 1 + a 0 + + r -1 a -1 + r -2 a -2 +…+ r -(m-1) a -(m-1) + r -m a -m
4
4 Number Base Representations Decimal system –Base, or radix 10 power of 10 –10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 In general: a 5 a 4 a 3 a 2 a 1 a 0.a -1 a -2 a -3 = 10 5 a 5 + 10 4 a 4 +10 3 a 3 + 10 2 a 2 + 10 1 a 1 + 10 0 a 0 + 10 -1 a -1 + 10 -2 a -2 +10 -3 a -3 E.g.: Decimal 1734 = 5185.68 = 1 * 1000+ 7 * 100+ 3 * 10+ 4 5 * 1000+ 1 * 100+ 8 * 10+ 5+ 6 * 0.1+ 8 * 0.01
5
5 Number Base Representations Binary system –Base 2 power of 2 –2 digits only: 0, 1 b 5 b 4 b 3 b 2 b 1 b 0.b -1 b -2 b -3 = 2 5 b 5 + 2 4 b 4 +2 3 b 3 + 2 2 b 2 + 2 1 b 1 + 2 0 b 0 + 2 -1 b -1 + 2 -2 b -2 +2 -3 b -3 Most significant bit (MSB) Least significant bit (LSB)
6
6 Binary Example (101.001) 2 = 1 * 2 2 + 0 * 2 1 + 1 * 2 0 + 0 * 2 -1 + 0 * 2 -2 + 1 * 2 -3 How much in decimal? = 1 * 4 + 1 + 1/8 = 5 + 0.125 = 5.125 Conversion from binary to decimal: add the coefficients multiplied by the powers
7
7 Number Base Representations Octal –8 digits: 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal –16 digits: 0, 1, …, 9, A (10), B (11), C (12), D (13), E(14), F(15) E.g.: (436.5) 8 = 4 * 8 2 + 3 * 8 + 6 + 5 * 8 -1 = (286.625) 10 (1CE8) 16 = 1 * 16 3 + 12 * 16 2 + 14 * 16 + 8 = (7400) 10
8
8 Powers of 2 Very useful in digital design Common names: 2 10 – Kilo (K) 2 20 – Mega (M) 2 30 – Giga (G) 2 40 – Tera (T) Used for computer capacity n2n2n 01 12 24 38 416 532 664 7128 8256 9512 101024
9
9 Let’s Count DecimalBinary (base 2)Octal (base 8)Hexa (base 16) 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 0000 0010 0001 0011 0100 0101 0110 1000 0111 00 1010 1001 1011 1100 1101 1110 1111 0 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 1 3 2 4 5 7 6 8 9 A B C D E F
10
10 Subtraction Method for Converting Decimal to Binary Goal –Converting from Decimal to Binary Idea –Put 1s in positions such that the binary weights add up to the decimal quantity –Work from left to right –Right to left – may fill in 1s that shouldn’t be there – try it. Easy for small numbers Desired decimal number: 12 12481632 1 =32 too much 12481632 0 =16 too much 1 a 12481632 0 =8 ok, keep going 01 12481632 0 =8+4=12 DONE 011 12481632 0 answer 01100 12481632
11
11 Subtraction Method for Converting Decimal to Binary Variant of previous method –Useful for big numbers Idea: –Subtract a selected binary weight from the quantity to be converted –With the remaining quantity, we start subtracting again (from the present binary position) –Stop when remaining quantity is 0 Remaining quantity: 12 12481632 1 32 is too much 12481632 0 16 is too much 1 a 12481632 0 12 – 8 = 4 01 12481632 0 4-4=0 DONE 011 12481632 0 answer 01100 12481632
12
12 Subtraction Method Example Convert the number “23” from decimal to binary 23 -16 7 Remaining quantityBinary Number 23 32168421 000000 32 0 16 1 8 0 4 0 2 0 1 0 7 -4 3 3 -2 1 32 0 16 1 8 0 4 1 2 1 1 0 32 0 16 1 8 0 4 1 2 1 1 11 0 Done! 23 in decimal is 10111 in binary. 32 0 16 1 8 0 4 1 2 0 1 0 8 is more than 7, can’t use
13
13 Decimal To Binary Conversion (Integer) 1.Divide the number by 2 quotient + remainder 2.Divide all successive quotients by 2 and record the remainders 3.Take the remainders in inverse order (end to beginning) binary number E.g.: 179 2 = 89 remainder 1 2 = 44 remainder 1 2 = 22 remainder 0 2 = 11 remainder 0 2 = 5 remainder 1 2 = 2 remainder 1 2 = 1 remainder 0 2 = 0 remainder 1 LSB MSB Result: 10110011 2
14
14 Decimal To Binary Conversion (Radix Point) 1.Multiply the number by 2 integer and fraction 2.Multiply the successive fractions by 2 and record the integer values 3.When the fraction becomes 0, take the integers in order (beginning to end) binary number E.g.: 0.6875 2 = Integer 1 fraction 0.3750 2 = integer 0 fraction 0.7500 2 = integer 1 fraction 0.5000 2 = integer 1 fraction 0 LSB Result: (0.1011) 2 MSB
15
15 Decimal to Octal/Hexa Conversion Same as decimal to binary, only division by 8, respectively 16 E.g. : 467 8 = E.g. : 3417 16 = 58 remainder 3 8 = 7 remainder 2 8 = 0 remainder 7 213 remainder 9 16 = 13 remainder 5 16 = 0 remainder 13 LSB MSB Result: (723) 8 LSB MSB Result: (D59) 16
16
16 Decimal to Octal – Radix Point Use multiplication method, by 8 E.g.: (0.513) 10 8 = Integer 4 fraction 0.104 8 = integer 0 fraction 0.832 8 = integer 6 fraction 0.656 8 = integer 5 fraction 0.248 LSB Result: (0.406517) 8 MSB 8 = integer 1 fraction 0.984 8 = integer 7 fraction 0.872 Could continue, but we stop when reaching desired floating point accuracy
17
17 Range of Representable Numbers How many numbers can we represent with n bits? 2 n numbers, in range 0 to 2 n -1 General base case: with n digits in base r r n numbers, in range 0 to r n - 1 E.g. : with 3 digits in base 10 –Can have 000-999: 10 3 = 1000 numbers
18
18 Binary, Octal, Hexa - Conversions Binary, Octal & Hexa have an interesting relation 2 3 = 8 2 4 = 16 Each octal digit corresponds to 3 binary digits Each hexa digit corresponds to 4 binary digits
19
19 Binary-Octal Conversion Partition the binary number into groups of three digits each, starting from the binary point, going right and left E.g. (10111011001.111100000110) 2 = 00101111110111100000110. 13727406. = (2731.7406) 8
20
20 Binary-Hexa Conversion Partition the binary number into groups of four digits each, starting from the binary point, going right and left E.g. (10111011001. 111100000110) 2 = 1001110110111110000. 9D5F06. = (5D9.F06) 16 0110
21
21 Octal(Hexa)-Binary Conversion Octal: substitute each digit with its 3-digit binary equivalent E.g. (1234) 8 = Hexa: substitute each digit with its 4-digit binary equivalent E.g. (C0DE) 16 = 001010011100 0000110011011110
22
22 Advantages of Hexa Representation Hexadecimal numbers can represent binary information more compactly Hexa requires a quarter of the digits needed in binary Four binary digits = one hexa digit
23
23 Summary of Conversions Decimal to (binary, octal, hexa) –Division by (or multiplication with) 2, 8, 16 respectively Binary to: –Octal: substitute groups of 3 digits –Hexa: substitute groups of 4 digits –Decimal: sum up coefficients * powers of 2 Octal to: –Binary: substitute digits with 3-digit binary Hexa to: –Binary: substitute digits with 4-digit binary Octal to hexa: –Convert to binary, then to the other base
24
24 Operations with Binary Numbers Addition –Similar technique as decimal 1 0 1 1 1 1 1 0 1 0 0 0 1 1 0 1 1 111110000 1000111 Carry: 190 + + 141 331 More examples: –10101101 + 00101100 (173 + 44) –01111111 + 00111111 (127 + 63) –10101010 + 01010101 (170 + 85)
25
25 Operations with Binary Numbers Multiplication –Similar technique as decimal 1 0 1 1 1 1 0 1 11011001 11** 13 143 1 0 1 1 0 0 1 0 1 1
26
26 Operations with Binary Numbers Subtraction Usual arithmetic: –Check the signs of operands –If the same sign, perform addition, keep the sign –If different sign, check which operand is bigger, subtract from it, and keep the sign of the bigger operand These computations are hard to perform by a digital circuit
27
27 Readings Chapter 1: –Sections 1.3-1.5
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.