Binary Number Systems and Codes ECEn 224 02
Binary Number Systems and Codes ECEn 224 02 NUMBERS Page 1 © 2003 -2008 BYU
Positional Numbers • What does 5132. 13 really mean? • Depends on the number base! • Assuming base 10: 5132. 1310 = 5 x 103 + 1 x 102 + 3 x 101 + 2 x 100 + 1 x 10 -1 + 3 x 10 -2 • Assuming base 6: 5132. 136 = 5 x 63 + 1 x 62 + 3 x 61 + 2 x 60 + 1 x 6 -1 + 3 x 6 -2 • We often use a subscript to indicate the base. ECEn 224 02 NUMBERS Page 2 © 2003 -2008 BYU
Positional Number Examples 527. 4610 = (5 x 102) + (2 x 101) + (7 x 100) + (4 x 10 -1) + (6 x 10 -2) 527. 468 = (5 x 82) + (2 x 81) + (7 x 80) + (4 x 8 -1) + (6 x 8 -2) 527. 465 = illegal why? 1011. 112 = (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) + (1 x 2 -1) + (1 x 2 -2) This works for binary as well… ECEn 224 02 NUMBERS Page 3 © 2003 -2008 BYU
Conversion from Binary Convert 101011. 112 to base 10: 101011. 11 = 1 x 25 + 0 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 1 x 2 -1 + 1 x 2 -2 2 = 32 + 0 + 8 + 0 + 2 + 1 + ½ + ¼ = 43. 7510 ECEn 224 02 NUMBERS Page 4 © 2003 -2008 BYU
Convert 11410 to binary: 1 x 26 1 x 25 1 x 24 0 x 23 0 x 22 Read this way 114 - 64 50 - 32 18 - 16 2 - 0 2 - 2 0 - 0 0 11410 = 11100102 1 x 21 0 x 20 This method also works for fractional numbers. ECEn 224 02 NUMBERS Page 5 © 2003 -2008 BYU
2 114 2 57 R 0 2 28 R 1 2 14 R 0 2 7 R 0 2 3 R 1 2 1 R 1 0 R 1 Read this way An Alternate Method ECEn 224 11410 = 11100102 02 NUMBERS Page 6 © 2003 -2008 BYU
Converting fractions from base 10 to binary: Convert 0. 710 to binary Read this way 0. 7 x 2 (1). 4 x 2 0. 710 = 0. 1 0110 … 2 (0). 8 x 2 (1). 6 x 2 (1). 2 x 2 (0). 4 x 2 process starts repeating here (0). 8 ECEn 224 02 NUMBERS Page 7 © 2003 -2008 BYU
Convert 114. 710 to binary: 1 x 26 1 x 25 1 x 24 0 x 23 0 x 22 1 x 21 Read this way 114. 7 - 64 50. 7 - 32 18. 7 - 16 2. 7 -0 2. 7 -2 0. 7 -0 0. 7 - 0. 5 0. 2 - 0. 0 0. 2 - 0. 125 0. 075 … 0 x 20 We could use the first technique. 11210 = 1110010. . . 2 1 x 2 -1 0 x 2 -2 1 x 2 -3 ECEn 224 02 NUMBERS Page 8 © 2003 -2008 BYU
Convert 114. 710 to binary: 0. 7 x 2 114 2 57 R 0 2 28 R 1 2 14 R 0 2 7 R 0 2 3 R 1 2 1 R 1 0 R 1 (1). 4 x 2 Read this way 2 Or we could combine the second and third techniques. (0). 8 x 2 (1). 6 x 2 11210 = 1110010. 10110. . . 2 (1). 2 x 2 (0). 4 x 2 (0). 8 ECEn 224 02 NUMBERS Page 9 © 2003 -2008 BYU
Hexadecimal • Commonly used for binary data – 1 hex digit 4 binary digits (bits) • Need more digits than just 0 -9 – Use 0 -9, A-F • A-F are for 10 -15 FA 216 = 15 x 162 + 10 x 161 + 2 x 160 FA 216 = 1111 1010 0010 Each group of 4 bits 1 hex digit ECEn 224 02 NUMBERS Page 10 © 2003 -2008 BYU
Other Notations For Binary and Hex • Binary – 101102 – 10110 b – 0 b 10110 • Hexadecimal – – 57316 0 x 573 h 16#573 ECEn 224 02 NUMBERS Page 11 © 2003 -2008 BYU
Other Codes BCD ASCII Gray ECEn 224 02 NUMBERS Page 12 © 2003 -2008 BYU
Binary Coded Decimal (BCD) Convert 249610 to BCD Code 2 4 9 6 0 0 1 0 1 1 0 Note this is very different from converting to binary which yields: 1 0 0 1 1 1 0 0 02 ECEn 224 02 NUMBERS Page 13 © 2003 -2008 BYU
Binary Coded Decimal (BCD) • Why use BCD? • In some applications it may be easier to work with • Financial institutions must be able to represent base 10 fractions (e. g. , 1/10) – 0. 110 = 0. 0011001100… 2 – Using BCD ensures that numeric results are identical to base 10 results ECEn 224 02 NUMBERS Page 14 © 2003 -2008 BYU
Binary Codes ASCII Code • ASCII American Standard Code for Information Interchange • ASCII is a 7 -bit code used to represent letters, symbols, and terminal codes • There also Extended ASCII codes, represented by 8 -bit numbers • Terminal codes include such things as: Tab (TAB) Line feed (LF) Carriage return (CR) Backspace (BS) Escape (ESC) And many more! ECEn 224 02 NUMBERS Page 15 © 2003 -2008 BYU
Binary Codes ASCII Code ECEn 224 02 NUMBERS Page 16 © 2003 -2008 BYU
Binary Codes Extended ASCII Code ECEn 224 02 NUMBERS Page 17 © 2003 -2008 BYU
Binary Codes ASCII Code (partial) Convert “help” to ASCII h e l p 1101000 1100101 1101100 1111000 0 x 68 ECEn 224 0 x 65 0 x 6 C 0 x 70 02 NUMBERS Page 18 © 2003 -2008 BYU
Binary Codes Gray Code • Only one bit changes with each number increment • Not a weighted code • Useful for interfacing to some physical systems ECEn 224 02 NUMBERS Page 19 © 2003 -2008 BYU
Gray Codes are Not Unique ECEn 224 02 NUMBERS Page 20 © 2003 -2008 BYU
Codes - Summary • Bits are bits… – Modern digital devices represent everything as collections of bits – A computer is one such digital device • You can encode anything with sufficient 1’s and 0’s – Text (ASCII) – Computer programs (C code, assembly code, machine code) – Sound (. wav, . mp 3, …) – Pictures (. jpg, . gif, . tiff) ECEn 224 02 NUMBERS Page 21 © 2003 -2008 BYU
- Slides: 21