200 likes | 414 Views
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…
E N D
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 (4x1000) 4000 three units of a hundred (3x100) 300 five units of ten (5x10) 50 seven units of one (7x1) 7 4 x103 + 3 x 102 + 5 x 101 + 7 x 100 5743 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: dn-1dn-2…d2d1d0 its definition dn-1 x bn-1 + dn-2 x bn-2 + … + d2 x b2+ d1 x b1 + d0 x b0 Examples: Base Digits 2 0, 1 5 0, 1, 2, 3, 4 8 0, 1, 2, 3, 4, 5, 6, 7 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Binary, Octal and HexadecimalComparison of first natural numbers in four different bases etc...
Arithmetic in other basesAll the familiar rules of pencil-and-paper decimal arithmetic carry over to any other base Decimal Grid Addition 46 101110 + 27 + 11011 Subtraction 5037 - 95 57 111001 - 6 - 110 Binary Grid
Octal Grid Hexadecimal Grid
Examples of arithmetic In Octal: 3754 76312 +6317 + 4634 In Hexadecimal: 3B6F 89FCD +5743 + 9FD In Decimal: 123 + 45 +3682 + 12 + 654
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 101011 = 1 x 25 + 0 x 24+ 1 x 23+ 0x 22+ 1 x 21+ 1 x 20 = 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 ÷ 2 86 1 1 86 ÷ 2 430 01 43 ÷ 2 211 101 21 ÷ 2 101 1101 10 ÷ 2 5 0 01101 5 ÷ 2 21 101101 2 ÷ 2 1 0 0101101 1 ÷ 2 01 10101101
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 1011010111 = 001 011 010 111 = 1327 (octal) • Binary to Hexadecimal • Group bits into fours, right to left • Convert each group into a hexadecimal digit • Example 1011001011 = 0010 1100 1011 = 2CB (hexadecimal)
Conversion between Binary and Octal/Hexadecimal • Octal to Binary • Convert each digit to a three-bit binary representation • Example 705 = 111 000 101 = 111000101 (binary) • Hexadecimal to Binary • Convert each digit to a four-bit binary representation • Example 10AF = 0001 0000 1010 1111 = 0001000010101111 (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