Digits range: 0 -> (Base
Download
Report
Transcript Digits range: 0 -> (Base
Introduction to Binary, Octal and
Hexadecimal Numbers
Thaddeus Konar
4/3/2016 Slide # 1
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Decimal Integers
8934098798347298763287632
There is nothing ‘unique’ about
number 10, but because we have 10
fingers, the decimal notation (from
09832198798237986498762380236409
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)
4576
8374567301
4/3/2016 Slide # 2
9654327
78543
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:
…,104 ,103, 102, 101, 100
(Please remember that any number X to zero (0) power equals 1!)
X0 = 1
4/3/2016 Slide # 3
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*100)+(4*101)+(8*102)+(7*103)
4/3/2016 Slide # 4
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Decimal Integers (Cont)
What does 58345 ‘really’ mean:
58345
5*1
4 * 10
3 * 100
8 * 1000
5 * 10000
=5
=40
=300
=8000
=50000
=58345
4/3/2016 Slide # 5
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, …) (100, 101 , 102 , …)
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
4/3/2016 Slide # 6
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
General Notation
Any number is represented by combination of single
digits Dx, where x is the position of the digit counting
from the right. The value of Dx can be only the digits
between (and including) 0 and (Base-1).
…D5D4D3D2D1D0
Using our example decimal number 7845
D0 =5,
4/3/2016 Slide # 7
D1=4,
D2=8,
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
and D3 =7
General Notation (cont)
We can see that any number really means:
(D0*B0)+(D1*B1)+(D2*B2)+(D3*B3)+…(Dn*Bn)
In our example number 7845 (base 10) means:
(5*100)+(4*101)+(8*102)+(7*103)=5+40+800+7000
4/3/2016 Slide # 8
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
4/3/2016 Slide # 9
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.
4/3/2016 Slide # 10
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):
(D0*B0)+(D1*B1)+(D2*B2)+(D3*B3)+…(Dn*Bn)
B0=1, B1=2, B2=4, B3 =8, B4=16, B5=32, B6 =64…
Lets look at the binary number 101110
D0=0, D1=1, D2=1, D3=1, D4=0, D5=1
4/3/2016 Slide # 11
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Binary Integers 4
…101110 means:
(0*20)+(1*21)+(1*22)+(1*23)+(0*24)+(1*25) =
(0*1)+(1*2)+(1*4)+(1*8)+(0*16)+(1*32) = 4610
Here are the first few binary numbers:
00002 = 010
01002 = 410
10002 = 810
11002 = 1210 100002 = 1610
00012 = 110
01012 = 510
10012 = 910
11012 = 1310 100012 = 1710
00102 = 210
01102 = 610
10102 = 1010
11102 = 1410 100102 = 1810
00112 = 310
01112 = 710
10112 = 1110
11112 = 1510 100112 = 1910
4/3/2016 Slide # 12
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Binary Conversion Example
Convert binary number 10111 to decimal:
10111
1*1
1*2
1*4
0*8
1 * 16
=1
=2
=4
=0
=16
=23
4/3/2016 Slide # 13
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Convert binary number to decimal:
10111001
1*1
=1
0*2
=0
0*4
=0
1*8
=8
1 * 16
=16
1 * 32
0 * 64
1 * 128
=32
=0
=128
=185
4/3/2016 Slide # 14
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
4/3/2016 Slide # 15
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 -> Base1).
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.
4/3/2016 Slide # 16
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Octal Integers 3
In octal integers Base = 8.
Please recall the formula:
(D0*B0)+(D1*B1)+(D2*B2)+(D3*B3)+…(Dn*Bn)
B0=1, B1=8, B2=64, B3 =512, B4=4096…
Lets look at the octal number 4153
D0=3, D1=5, D2=1, D3=4
4/3/2016 Slide # 17
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Octal Integers 4
…4153 means:
(3*80)+(5*81)+(1*82)+(4*83) =
(3*1)+(5*8)+(1*64)+(4*512) = 215510
Here are the first few octal numbers:
00008 = 010
00048 = 410
00108 = 810
00148 = 1210
00208 = 1610
00018 = 110
00058 = 510
00118 = 910
00158 = 1310
00218 = 1710
00028 = 210
00068 = 610
00128 = 1010
00168 = 1410
00228 = 1810
00038 = 310
00078 = 710
00138 = 1110
00178 = 1510
00238 = 1910
4/3/2016 Slide # 18
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
4/3/2016 Slide # 19
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.
4/3/2016 Slide # 20
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Hex Integers 3
In Hex integers Base = 16.
Please recall the formula:
(D0*B0)+(D1*B1)+(D2*B2)+(D3*B3)+…(Dn*Bn)
B0=1, B1=16, B2=256, B3 =4096, B4=65536…
Lets look at the octal number A59C
D0=C, D1=9, D2=5, D3=A
4/3/2016 Slide # 21
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Hex Integers 4
…A59C means:
(12*160)+(9*161)+(5*162)+(A*163) =
(12*1)+(9*16)+(5*256)+(10*4096) = 4239610
Here are the first few hex numbers:
00016 = 010
00416 = 410
00816 = 810
00C16 = 1210
01016 = 1610
00116 = 110
00516 = 510
00916 = 910
00D16 = 1310
01116 = 1710
00216 = 210
00616 = 610
00A16 = 1010
00E16 = 1410
01216 = 1810
00316 = 310
00716 = 710
00B16 = 1110
00F16 = 1510
01316 = 1910
4/3/2016 Slide # 22
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Relationship between Binary and
Octal Numbers
10110102 = 9010
Converting to Octal:
Binary: 001 011 010 = 9010
Octal:
1
3
2 = 9010
4/3/2016 Slide # 23
each octal digit is 3 bits
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Relationship between Binary and
Hex Numbers
10110102 = 9010
Converting to Hex:
Binary: 0101 1010 = 9010
Hex:
5
A = 9010
4/3/2016 Slide # 24
each hex digit is 4 bits
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Relationship between Binary,
Octal and Hex Numbers 1
1111011011100101101010110102
Converting to Octal:
111 101 101 110 010 110 101 011 010
7
5
5
6
2
6
5
3
2
Converting to Hex:
0111 1011 0111 0010 1101 0101 1010
7
B
7
2
D
5
A
4/3/2016 Slide # 25
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar
Relationship between Binary,
Octal and Hex Numbers 2
Decimal
Binary
Octal (3 binary digits)
Hex (4 binary digits)
0
00000
0
0
1
00001
1
1
2
00010
2
2
3
00011
3
3
4
00100
4
4
5
00101
5
5
6
00110
6
6
7
00111
7
7
8
01000
10
8
9
01001
11
9
10
01010
12
A
11
01011
13
B
12
01100
14
C
13
01101
15
D
14
01110
16
E
15
01111
17
F
16
10000
20
10
17
10001
21
11
18
10010
22
12
19
10011
23 (10 + 011)
13 (1 + 0011)
4/3/2016 Slide # 26
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
4/3/2016 Slide # 27
Binary, Octal and Hex Numbers
Copyright Thaddeus Konar