3.-number-system
3.-number-system
n 1 4 3 2 1 0
10 10 10 10 10 10
d n 1 d 4 d3 d 2 d1 d 0
Digit d0 is the least significant digit (LSD).
Digit dn-1 is the most significant digit (MSD). 3
Binary Number System
Base 2
Two Digits: 0, 1
Example: 10101102
Positional Number System
n 1 4 3 2 1 0
2 2 2 2 2 2
bn 1 b4 b3 b2 b1 b0
Binary Digits are called Bits
Bit bo is the least significant bit (LSB).
Bit bn-1 is the most significant bit (MSB).
4
Definitions
nybble = 4 bits
byte = 8 bits
(short) word = 2 bytes = 16 bits
(double) word = 4 bytes = 32 bits
(long) word = 8 bytes = 64 bits
1K (kilo or “kibi”) = 1,024
1M (mega or “mebi”) = (1K)*(1K) = 1,048,576
1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824
5
Hexadecimal Number System
Base 16
Sixteen Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Example: EF5616
Positional Number System
n 1 4 3 2 1 0
16 16 16 16 16 16
0000 0 0100 4 1000 8 1100 C
0001 1 0101 5 1001 9 1101 D
0010 2 0110 6 1010 A 1110 E
0011 3 0111 7 1011 B 1111 F
6
7
8
9
10
11
12
13
Number Conversions
14
Decimal to Binary Conversion
Method I:
Use repeated subtraction.
Subtract largest power of 2, then next largest, etc.
15
Decimal to Binary Conversion
Suppose x = 156410
Subtract 1024: 1564-1024 (210) = 540 n=10 or 1 in the (210)’s position
Subtract 512: 540-512 (29) = 28 n=9 or 1 in the (29)’s position
28=256, 27=128, 26=64, 25=32 > 28, so we have 0 in all of these positions
Thus:
156410 = (1 1 0 0 0 0 1 1 1 0 0)2
16
Decimal to Binary Conversion
Method II:
Use repeated division by radix.
2 | 1564 2|__24_
782
2|_____ R=0 12
2|_____ R=0
391
2|_____ R=0 6
2|_____ R=0
195
2|_____ R=1 3
2|_____ R= 0
97
2|_____ R=1 1 R=1
2|_____
48
2|_____ R=1 0 R=1
24 R = 0
Collect remainders in reverse order
11000011100
17
Binary to Hex Conversion
01 1 0 0 0 0 1 1 1 0 0
Pad with 0’s
If unsigned number
18
Hexadecimal to Binary Conversion
Example
(1 E 9 C)16
19
Decimal to Hex Conversion
Method II:
Use repeated division by radix.
16 | 1564
97
16|_____ R = 12 = C
6
16|_____
0
R=1
R=6
N = 61C 16
20