Dale & Lewis Chapter 2 Binary Numbers and Number Systems
Number categories Definition of −Number Unit of a mathematical system subject to arithmetic −Natural numbers 0, 1, 2, 3, 4… −Negative numbers Number less then 0, i.e. -1, -2, -3, -4… −Integers …-4, -3, -2, -1, 0, 1, 2, 3, 4… −Rational numbers Fraction of integers, except division by 0, i.e. ¼, ½, -7/13…
The idea of a positional number system 4357 four thousand, three hundred and fifty seven four units of a thousand ( 4 x 1000) 4000 three units of a hundred ( 3 x 100) 300 five units of ten ( 5 x 10) 50 seven units of one ( 7 x 1) 7 4 x x x x same digits, different positions, different number The position of each digit determines that digit’s contribution to the number.
The idea of a positional number system base: b any integer > 1 digits: 0, 1,..., b−1 number: d n-1 d n-2 …d 2 d 1 d 0 its definition d n-1 x b n-1 + d n-2 x b n-2 + … + d 2 x b 2 + d 1 x b 1 + d 0 x b 0 Examples: BaseDigits 20, 1 50, 1, 2, 3, 4 80, 1, 2, 3, 4, 5, 6, 7 100, 1, 2, 3, 4, 5, 6, 7, 8, 9 160, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Binary, Octal and Hexadecimal Comparison of first natural numbers in four different bases etc...
…So what base was used in the data in the Matrix movies?
Arithmetic in other bases All the familiar rules of pencil-and-paper decimal arithmetic carry over to any other base Addition Subtraction Decimal Grid Binary Grid
Octal Grid Hexadecimal Grid
Examples of arithmetic In Octal: In Hexadecimal: 3B6F89FCD FD In Decimal:
Conversion between Decimal and Binary Binary to Decimal −Use the definition of a number in a positional number system with base 2 −Evaluate the definition formula using decimal arithmetic Example = 1 x x x x x x 2 0 = 43 (decimal)
Conversion between Decimal and Binary Decimal to Binary −Repeatedly divide by 2 −Quotient Carries −Remainder is the next digit −Binary number is developed right to left Example (Quotient) (Remainder) (Binary) 173 ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷
Generalization: Conversion between Decimal and base b Base b to Decimal −Use the definition of a number in a positional number system with base b −Evaluate the definition formula using decimal arithmetic Decimal to base b −Repeatedly divide by b −Quotient carries −Remainder is the next digit −Base b number is developed right to left
Conversion between Binary and Octal/Hexadecimal Binary to Octal −Group bits into threes, right to left −Convert each group into an octal digit Example = = 1327 (octal) Binary to Hexadecimal −Group bits into fours, right to left −Convert each group into a hexadecimal digit Example = = 2CB (hexadecimal)
Conversion between Binary and Octal/Hexadecimal Octal to Binary −Convert each digit to a three-bit binary representation Example 705 = = (binary) Hexadecimal to Binary −Convert each digit to a four-bit binary representation Example 10AF = = (binary) Conversion tables can be reconstructed in the margins of a test paper when needed
What about converting between Octal and Hexadecimal? Hexadecimal is not base 8, so grouping won’t work as in binary octal or binary hexadecimal Octal to Hexadecimal −Convert octal to binary and then binary to hexadecimal Hexadecimal to Octal −Convert hexadecimal to binary and then to octal
DecimalBinaryOctalHexadecimal A B C D E F
ABCDEF A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0B0C0D0E0F A0A0B0C0D0E0F B0B0C0D0E0F A C0C0D0E0F A1B D0D0E0F A1B1C E0E0F A1B1C1D F0F A1B1C1D1E