© BYU 02 NUMBERS Page 1 ECEn 224 Binary Number Systems and Codes
© BYU 02 NUMBERS Page 2 ECEn 224 Positional Numbers What does really mean? Depends on the number base! Assuming base 10: = 5x x x x x x10 -2 Assuming base 6: = 5x x x x x x6 -2 We often use a subscript to indicate the base.
© BYU 02 NUMBERS Page 3 ECEn 224 Positional Number Examples = (5 x 10 2 ) + (2 x 10 1 ) + (7 x 10 0 ) + (4 x ) + (6 x ) = (5 x 8 2 ) + (2 x 8 1 ) + (7 x 8 0 ) + (4 x 8 -1 ) + (6 x 8 -2 ) = illegal why? = (1 x 2 3 ) + (0 x 2 2 ) + (1 x 2 1 ) + (1 x 2 0 ) + (1 x 2 -1 ) + (1 x 2 -2 ) This works for binary as well…
© BYU 02 NUMBERS Page 4 ECEn 224 Conversion from Binary Convert to base 10: = 1x x x x x x x x2 -2 = ½ + ¼ =
© BYU 02 NUMBERS Page 5 ECEn 224 Convert to binary: x x x x x x x = Read this way This method also works for fractional numbers.
© BYU 02 NUMBERS Page 6 ECEn An Alternate Method R 0 28 R 1 14 R 0 7 R 0 3 R 1 1 R 1 0 R = Read this way
© BYU 02 NUMBERS Page 7 ECEn 224 Converting fractions from base 10 to binary: Convert to binary 0.7 x 2 (1).4 x 2 (0).8 x 2 (1).6 x 2 (1).2 x 2 (0).4 x 2 (0).8 process starts repeating here = … 2 Read this way
© BYU 02 NUMBERS Page 8 ECEn 224 Convert to binary: We could use the first technique x x x x x x x x x x … Read this way =
© BYU 02 NUMBERS Page 9 ECEn 224 Convert to binary: Or we could combine the second and third techniques = R 0 28 R 1 14 R 0 7 R 0 3 R 1 1 R 1 0 R x 2 (1).4 x 2 (0).8 x 2 (1).6 x 2 (1).2 x 2 (0).4 x 2 (0).8 Read this way
© BYU 02 NUMBERS Page 10 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 FA2 16 = 15x x x16 0 FA2 16 = Each group of 4 bits 1 hex digit
© BYU 02 NUMBERS Page 11 ECEn 224 Other Notations For Binary and Hex Binary – –10110b –0b10110 Hexadecimal – –0x573 –573h –16#573
© BYU 02 NUMBERS Page 12 ECEn 224 Other Codes BCD ASCII Gray
© BYU 02 NUMBERS Page 13 ECEn 224 Binary Coded Decimal (BCD) Convert to BCD Code Note this is very different from converting to binary which yields:
© BYU 02 NUMBERS Page 14 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) – = … 2 –Using BCD ensures that numeric results are identical to base 10 results
© BYU 02 NUMBERS Page 15 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!
© BYU 02 NUMBERS Page 16 ECEn 224 Binary Codes ASCII Code
© BYU 02 NUMBERS Page 17 ECEn 224 Binary Codes Extended ASCII Code
© BYU 02 NUMBERS Page 18 ECEn 224 Binary Codes ASCII Code (partial) Convert “help” to ASCII h e l p x68 0x65 0x6C 0x70
© BYU 02 NUMBERS Page 19 ECEn 224 Binary Codes Gray Code Only one bit changes with each number increment Not a weighted code Useful for interfacing to some physical systems
© BYU 02 NUMBERS Page 20 ECEn 224 Gray Codes are Not Unique
© BYU 02 NUMBERS Page 21 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)