220 likes | 614 Views
Binary Number Systems and Codes. Positional Numbers. What does 5132.13 really mean? Depends on the number base! Assuming base 10: 5132.13 10 = 5 x10 3 + 1 x10 2 + 3 x10 1 + 2 x10 0 + 1 x10 -1 + 3 x10 -2 Assuming base 6:
E N D
Binary Number SystemsandCodes ECEn 224
Positional Numbers • What does 5132.13 really mean? • Depends on the number base! • Assuming base 10: 5132.1310 = 5x103 + 1x102 + 3x101 + 2x100 + 1x10-1 + 3x10-2 • Assuming base 6: 5132.136 = 5x63 + 1x62 + 3x61 + 2x60 + 1x6-1 + 3x6-2 • We often use a subscript to indicate the base. ECEn 224
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 = illegalwhy? 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
Conversion from Binary Convert 101011.112 to base 10: 101011.112 = 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20 + 1x2-1 + 1x2-2 = 32 + 0 + 8 + 0 + 2 + 1 + ½ + ¼ = 43.7510 ECEn 224
- 64 1x26 - 32 1x25 - 16 1x24 - 0 0x23 - 0 0x22 - 2 1x21 - 0 0x20 Convert 11410 to binary: 114 50 18 11410 = 11100102 2 Read this way 2 2 0 0 This method also works for fractional numbers. ECEn 224
2 2 2 2 2 2 2 An Alternate Method 114 57 R 0 28 R 1 11410 = 11100102 14 R 0 Read this way 7 R 0 3 R 1 1 R 1 0 R 1 ECEn 224
(0).8 (1).6 (1).2 process starts repeating here (0).4 (0).8 Converting fractions from base 10 to binary: Convert 0.710 to binary 0.7 x 2 (1).4 0.710 = 0.1 0110 0110 …2 x 2 x 2 Read this way x 2 x 2 x 2 ECEn 224
Convert 114.710 to binary: 114.7 - 64 1x26 50.7 - 32 1x25 18.7 - 16 1x24 2.7 - 0 0x23 2.7 - 0 0x22 2.7 - 2 1x21 0.7 - 0 0x20 0.7 - 0.5 1x2-1 0.2 - 0.0 0x2-2 0.2 - 0.125 1x2-3 0.075 … We could use the first technique. Read this way 11210 = 1110010.10...2 ECEn 224
2 2 2 2 2 2 2 (0).8 (1).6 (1).2 (0).4 (0).8 Convert 114.710 to binary: 0.7 x 2 114 (1).4 57 R 0 x 2 28 R 1 Or we could combine the second and third techniques. 14 R 0 x 2 7 R 0 Read this way 11210 = 1110010.10110...2 x 2 3 R 1 1 R 1 x 2 0 R 1 x 2 ECEn 224
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-15FA216 = 15x162 + 10x161 + 2x160FA216 = 1111 1010 0010 Each group of 4 bits 1 hex digit ECEn 224
Other Notations For Binary and Hex • Binary • 101102 • 10110b • 0b10110 • Hexadecimal • 57316 • 0x573 • 573h • 16#573 ECEn 224
Other Codes BCD ASCII Gray ECEn 224
Binary Coded Decimal(BCD) Convert 249610 to BCD Code 2 4 9 6 0 0 1 0 0 1 0 0 1 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 0 0 0 02 ECEn 224
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.00110011001100…2 • Using BCD ensures that numeric results are identical to base 10 results ECEn 224
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 are 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
Binary Codes ASCII Code ECEn 224
Binary Codes Extended ASCII Code ECEn 224
Binary CodesASCII Code (partial) Convert “help” to ASCII h e l p 1101000 1100101 1101100 1111000 0x68 0x65 0x6C 0x70 ECEn 224
Binary CodesGray Code • Only one bit changes with each number increment • Not a weighted code • Useful for interfacing to some physical systems ECEn 224
Gray Codes are Not Unique ECEn 224
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, .mp3, …) • Pictures (.jpg, .gif, .tiff) ECEn 224