Chapter 5 1 Number Systems
Why Binary System? • Computers are made of a series of switches • Each switch has two states: ON or OFF • Each state can be represented by a number – 1 for “ON” and 0 for “OFF”
2
Converting Base-2 to Base-10 ON/OFF
ON
OFF
OFF
ON
ON
(1 0 0 1 1) Exponent:
24
23
22
21
20
2
16 0 0 2 1 (19)10
Calculation:
+
+
3
+
+
=
• Number systems include decimal, binary, octal and hexadecimal • Each system have four number base Number System Base
Symbol
Binary
Base 2
B
Octal
Base 8
O
Decimal
Base 10
D
Hexadecimal
Base 16
H
4
Converting Decimal to Binary
Converting Binary to Decimal
Converting Binary to Octal 100011001010012
start
STEP ONE: Take the binary number and from right to left, group all placeholders in triplets. Add leading zeros, if necessary:
010
001
100 7
101 001
Example 2
0010 001 100 101 0012
= 214518
STEP TWO: Convert each triplet to its single-digit octal equivalent. (HINT: For each triplet, the octal conversion is the same as converting to a decimal number):
010
001
100
101
001
2
1
4
5
1
9
Converting Octal to Binary 435208 = 1000111010100002 STEP ONE: Take each octal digit and convert each digit to a binary triplet. Keep leading zeros:
4 100
3 0 011
5 101 10
2 010 0
0 000
Converting Decimal to Octal
Hexadecimal System • Sometimes, it is necessary to use a numbering system that has more than ten base digits • One such numbering system, hexadecimal, is useful on the Web • Hexadecimal number, a Base-16 numbering system, is used in specifying web colors
12
Hexadecimal Numbering ď Ž
There are new symbols for the Base-16 equivalents of the Base-10 numbers 10, 11, 12, 14 and 15. Examine:
DEC
0
1
2
3
4
5
6
7
HEX
0
1
2
3
4
5
6
7
DEC
8
9
10
11
12
13
14
15
HEX
8
9
A
B
C
D
E
F 13
Decimal 0 1 2 3 4 5 6 7 8 9
Hexadecimal
0 1 2 3 4 5 6 7 8 9
Octal 0 1 2 3 4 5 6 7 10 11
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
14
Decimal
Hexadecimal
Octal
Binary
10
A
12
1010
11
B
13
1011
12
C
14
1100
13
D
15
1101
14
E
16
1110
15
F
17
1111 15
Converting Hex to Binary • Convert a hexadecimal number to a binary number, • simply divided the binary number into 4-bit groups • substitute the corresponding four bits in binary for each hexadecimal digit in the number. • For example, convert ABCD to a binary value, The binary equivalent is: • ABCD= 1010 1011 1100 1101 16
Binary to Hex Conversion • Break the binary number into 4-bit groups from the Left to the right. • Convert the 4-bit binary number to its Hex equivalent. • For example, the binary value 101011111011 0010 will be written: • 1010 1111 1011 0010=AFB2
17
Example 2
Hex to Decimal Conversion • To convert from Hex to Decimal, • multiply the value in each position by its hex weight and • add each value. use the expansion form • AFB.2=10*163 +15*162 +11*16+2*16-1
19
Decimal to Hex Conversion • Repeated Division By 16 • Divide the decimal number by 16, and write the remainder on the side as the least significant digit. • This process is continued by dividing the quotient by 16 and writing the remainder until the quotient is 0. • the remainders represent the hex equivalent of the decimal number are written beginning at the least significant digit (right) and each new digit is written to the next more significant digit (the left) of the previous digit.
20
Example convert 196710 to Hex Division
Quotient
Remainder
Hex Number
1967/16
122
15
F
122/16
7
10
AF
7/16
0
7
7AF
Then
(1967)10 =(7AF)16 21
Convert (1967.0626)10 to B,O,H Division
Quotient
Remainder
Hex Number
1967/8
245
7
7
245/8
30
3
37
30/8
3
6
376
3/8
0
3
3637
(1967)10=
(3537)8
0.062510 = .048
(1967.0626)10= (3637.04) 22 8
Binary Addition • • • •
0+0=0 0+1=1 1+0=1 1 + 1 = 10
+
0
1
0
0
1
1
1
10
23
Hex. & Octal • Converting Hex to Octal
?
• Converting Octal to Hex
?
Multiply Binary numbers
0*0=0 0*1=0 1*0=0 1*1=1
*
0
1
0
0
0
1
0
1
25
– 1111 carry – 111101 100111+ • 1100100
1 1 1 (carry) 01101 1 0 1 1 1+ ------------100100
26
Multiply 1011 and 1010 –
1 0 1 1 ×1 0 1 0 --------------0 0 0 0 1 0 1 1 0 0 0 0 +1 0 1 1 -----------------1 1 01 1 1 0 27
Multiply Example
1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 -----------------------------------1 0 1 1 1 1 0 1 1
28