1/15/2015 Slide # 1 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Introduction to Binary, Octal and Hexadecimal Numbers Thaddeus Konar
1/15/2015 Slide # 2 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Decimal Integers There is nothing ‘unique’ about number 10, but because we have 10 fingers, the decimal notation (from Latin decem and Greek Deka: 10) seems ‘natural’ to us. If the world would be like Simpsons (and I am glad it is not) the natural notation would be octal (8 fingers)
1/15/2015 Slide # 3 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Decimal Integers Each digit (counting from the right) represents next power of ten, the rightmost digit represents 1s, next digit represents 10s, next 100s, and so on: …,10000, 1000, 100, 10, 1 which is the same as: …,10 4,10 3, 10 2, 10 1, 10 0 (Please remember that any number X to zero (0) power equals 1!) X 0 = 1
1/15/2015 Slide # 4 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Decimal Integers (cont) 7845 means: (5*1)+(4*10)+(8*100)+(7*1000) and this is same as: (5*10 0 )+(4*10 1 )+(8*10 2 )+(7*10 3 )
1/15/2015 Slide # 5 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Decimal Integers (Cont) What does ‘really’ mean: * 1 4 * 10 3 * 100 =5 =40 =300 8 * 1000= * =50000 =58345
1/15/2015 Slide # 6 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Decimal Integers (cont) Lets look at the properties of the decimal integers: Base = 10 (1, 10, 100, …) (10 0, 10 1, 10 2, …) Digits range: 0 -> 9 (0,1,2,3,4,5,6,7,8,9) Number of values represented by a single digit: 10 Please note that number of digits equals Base, and range goes from zero to (Base –1). Digits range: 0 -> (Base - 1) Number of values represented by a single digit: Base
1/15/2015 Slide # 7 Binary, Octal and Hex Numbers Copyright Thaddeus Konar General Notation Any number is represented by combination of single digits D x, where x is the position of the digit counting from the right. The value of D x can be only the digits between (and including) 0 and (Base-1). …D 5 D 4 D 3 D 2 D 1 D 0 Using our example decimal number 7845 D 0 =5, D 1 =4, D 2 =8, and D 3 =7
1/15/2015 Slide # 8 Binary, Octal and Hex Numbers Copyright Thaddeus Konar General Notation (cont) We can see that any number really means: (D 0 *B 0 )+(D 1 *B 1 )+(D 2 *B 2 )+(D 3 *B 3 )+…(D n *B n ) In our example number 7845 (base 10) means: (5*10 0 )+(4*10 1 )+(8*10 2 )+(7*10 3 )=
1/15/2015 Slide # 9 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Binary Integers 1 Just as the each digit (position) in decimal integer is represented by the power of 10, binary integers are numbers where each digit is represented by the power of 2 (Base = 2). Digits range: 0 -> (Base - 1) Number of values represented by a single digit: Base Digits range: 0 -> 1(0,1) Number of values represented by a single digit: 2
1/15/2015 Slide # 10 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Binary Integers 2 In the decimal number the digits could be 0,1,2,3,4,5,6,7,8,9. (0 -> Base-1). As we can see the binary number digits could only be either 0 or 1 (0 ->Base-1). The single decimal number can represent 10 values, and the single binary number can represent only 2 values.
1/15/2015 Slide # 11 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Binary Integers 3 Binary integer will be a combination of 1s and 0s. Please recall the formula (and remember that now Base=2): (D 0 *B 0 )+(D 1 *B 1 )+(D 2 *B 2 )+(D 3 *B 3 )+…(D n *B n ) Lets look at the binary number D 0 =0, D 1 =1, D 2 =1, D 3 =1, D 4 =0, D 5 =1 B 0 =1, B 1 =2, B 2 =4, B 3 =8, B 4 =16, B 5 =32, B 6 =64…
1/15/2015 Slide # 12 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Binary Integers 4 Here are the first few binary numbers: … means: (0*2 0 )+(1*2 1 )+(1*2 2 )+(1*2 3 )+(0*2 4 )+(1*2 5 ) = (0*1)+(1*2)+(1*4)+(1*8)+(0*16)+(1*32) = = = = = = = = = = = = = = = = = = = = = 19 10
1/15/2015 Slide # 13 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Binary Conversion Example Convert binary number to decimal: * 1 1 * 2 1 * 4 =1 =2 =4 0 * 8=0 1 * 16 =16 =23
1/15/2015 Slide # 14 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Convert binary number to decimal: * 1 0 * 2 0 * 4 =1 =0 1 * 8=8 1 * 16 =16 =185 1 * 32=32 0 * 64=0 1 * 128=128
1/15/2015 Slide # 15 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Octal Integers 1 Just as the each digit (position) in decimal integer is represented by the power of 10, in binary integer each digit represents power of 2, in octal numbers each digit is represented by the power of 8 (Base = 8). Digits range: 0 -> (Base - 1) Number of values represented by a single digit: Base Digits range: 0 -> 7(0,1, 2, 3, 4, 5, 6, 7) Number of values represented by a single digit: 8
1/15/2015 Slide # 16 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Octal Integers 2 In the decimal number the digits could be 0,1,2,3,4,5,6,7,8,9. (0 -> Base-1), in binary 0,1 (Base-1), so as you can suspect in octal numbers the digits would be 0,1,2,3,4,5,6,7 (0 -> Base- 1). The single decimal number can represent 10 values, the single binary number can represent only 2 values, and single octal number can represent 8 values.
1/15/2015 Slide # 17 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Octal Integers 3 In octal integers Base = 8. Please recall the formula: (D 0 *B 0 )+(D 1 *B 1 )+(D 2 *B 2 )+(D 3 *B 3 )+…(D n *B n ) Lets look at the octal number 4153 D 0 =3, D 1 =5, D 2 =1, D 3 =4 B 0 =1, B 1 =8, B 2 =64, B 3 =512, B 4 =4096…
1/15/2015 Slide # 18 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Octal Integers 4 Here are the first few octal numbers: …4153 means: (3*8 0 )+(5*8 1 )+(1*8 2 )+(4*8 3 ) = (3*1)+(5*8)+(1*64)+(4*512) = = = = = = = = = = = = = = = = = = = = = 19 10
1/15/2015 Slide # 19 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Hexadecimal (Hex) Integers 1 Just as the each digit (position) in decimal integer is represented by the power of 10, in binary integer - power of 2, in octal numbers - power of 8, and in hex integers – power of 16 (Base = 16). Digits range: 0 -> (Base - 1) Number of values represented by a single digit: Base Digits range: 0 -> 15 (0,1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) Number of values represented by a single digit: 16
1/15/2015 Slide # 20 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Hex Integers 2 In the decimal number the digits could be 0,1,2,3,4,5,6,7,8,9. (0 -> Base-1), in binary 0,1 (Base-1), in octal 0,1,2,3,4,5,6,7. (0 -> Base-1). In hex numbers the digits would be 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (0 -> Base-1). The letters A through F represent the decimal numbers 10 to 15. The single decimal number can represent 10 values, the single binary number can represent only 2 values, the single octal number can represent 8 values, and the single hex number can represent 16 values.
1/15/2015 Slide # 21 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Hex Integers 3 In Hex integers Base = 16. Please recall the formula: (D 0 *B 0 )+(D 1 *B 1 )+(D 2 *B 2 )+(D 3 *B 3 )+…(D n *B n ) Lets look at the octal number A59C D 0 =C, D 1 =9, D 2 =5, D 3 =A B 0 =1, B 1 =16, B 2 =256, B 3 =4096, B 4 =65536…
1/15/2015 Slide # 22 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Hex Integers 4 Here are the first few hex numbers: …A59C means: (12*16 0 )+(9*16 1 )+(5*16 2 )+(A*16 3 ) = (12*1)+(9*16)+(5*256)+(10*4096) = = = = C 16 = = = = = D 16 = = = = A 16 = E 16 = = = = B 16 = F 16 = = 19 10
1/15/2015 Slide # 23 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Relationship between Binary and Octal Numbers = Converting to Octal: Binary: = Octal: = each octal digit is 3 bits
1/15/2015 Slide # 24 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Relationship between Binary and Hex Numbers = Converting to Hex: Binary: = Hex: 5 A = each hex digit is 4 bits
1/15/2015 Slide # 25 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Relationship between Binary, Octal and Hex Numbers Converting to Octal: Converting to Hex: B 7 2 D 5 A
1/15/2015 Slide # 26 Binary, Octal and Hex Numbers Copyright Thaddeus Konar Relationship between Binary, Octal and Hex Numbers 2 DecimalBinaryOctal (3 binary digits)Hex (4 binary digits) A B C D E F ( )13 ( )
1/15/2015 Slide # 27 Binary, Octal and Hex Numbers Copyright Thaddeus Konar "nobody wants to be a 0 but everybody wants to be a 1" Laurie Anderson - Home of the Brave