Chapter 2 Binary Numbers and Number Systems Number Categories – Ch. 2.1 Definition of number natural numbers negative numbers integers rational numbers Positional notation – Ch. 2.2 base: b any integer > 1 digits: 0, 1, ..., b−1 number d n 1d n 2 d 2 d1d 0 its definition d n 1 b n 1 d n 2 b n 2 d 2 b 2 d1 b1 d 0 b 0 Examples: base 2 5 8 10 16 digits 0,1 0,1,2,3,4 0,1,2,3,4,5,6,7 0,1,2,3,4,5,6,7,8,9 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F CSE 1520 – Week 2.2 January 15, 2013 page 1 Binary, Octal and Hexadecimal Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Binary Octal 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000 10001 10010 10011 10100 10101 10110 10111 Hexadecimal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 etc. Arithmetic in Other Bases All the familiar rules and techniques of pencil-and-paper decimal arithmetic carry over to any other base. Addition 46 + 27 Subtraction 101110 + 11011 CSE 1520 – Week 2.2 5037 − 95 57 − 6 January 15, 2013 111001 − 110 page 2 Conversions between Decimal and Binary Binary to Decimal Technique - use the definition of a number in a positional number system with base 2 - evaluate the definition formula using decimal arithmetic Example 543210 ← position = corresponding power of 2 |||||| 101011 = 1 25 + 0 2 4 + 1 23 + 0 2 2 + 1 21 + 1 2 0 = 43 (decimal) generalize to Octal to Decimal, Hexadecimal to Decimal Decimal to Binary Technique - repeatedly divide by 2 - remainder is the next digit - binary number is developed right to left Example 173 86 43 21 10 5 2 1 2 2 2 2 2 2 2 2 86 43 21 10 5 2 1 0 1 0 1 1 0 1 0 1 1 01 101 1101 01101 101101 0101101 10101101 generalize to Decimal to Octal, Decimal to Hexadecimal CSE 1520 – Week 2.2 January 15, 2013 page 3 Conversions between Binary and Octal/Hexadecimal Binary to Octal Technique - group bits into threes, right to left - convert each such group to an octal digit Example 1011010111 = 1 011 010 111 = 1327 (octal) Binary to Hexadecimal Technique - group bits into fours, right to left - convert each such group to a hexadecimal digit Example 1011001011 = 10 1100 1011 = 2CB (hexadecimal) Octal to Binary Technique - convert each octal digit to a three-bit binary representation Example 705 = 111 000 101 = 111000101 (binary) CSE 1520 – Week 2.2 January 15, 2013 page 4 Hexadecimal to Binary Technique - convert each octal digit to a four-bit binary representation Example 10AF = 0001 0000 1010 1111 = 1000010101111 (binary) What about converting between Octal and Hexadecimal? CSE 1520 – Week 2.2 January 15, 2013 page 5