Number Systems
Number Systems
char c=’6’;
int c=6;
UNICODE – along with ASCII it includes other codes for other
languages, \u0000 – default value of a character which is zero(0)
Memory allocation
1 byte – 8 bits
2 bytes – 16 bits
1024 bytes – 1 Kb
1024 Kb = 1 Mb
1024 Mb = 1 Gb
Binary number
101010 =
MSB 0 1 0 1 0 1 0
26 25 24 23 22 21 20
(1010101)2 = ( ) 10
Home work
Convert binary to decimal
1. 00001111 = 15
2. 10101111 = 175
3. 11110001 = 241
4. 10101 = 21
5. 10011 = 19
6. 111111 = 63
Home work
Convert the following binary numbers to their decimal equivalent
1. (101011) 2- (43)10
2. 110011 - 51
3. 11110000 - 240
4. 101110011 - 371
5. 1010000 - 80
6. 100100111 – 295
(35)10 = (100011)2
1+2+0+0+0+32 = 35
(56)10 = (111000)2
Examples
1. (34)10 – (100010 )2
2. (105)10 = (1101001)2
3. (77)10 = (1001101)2
4. (80)10 = (1010000)2
10/8 q- 1, rem-2
1/8 q – 0 rem 1
(1234)10 = (2322)8
154/8 q- 19 rem – 2
19/8 q- 2 rem 3
1. (786)10 = (1422)8
2. 2345= (4451)8
3. 876 = (1554)8
converting octal to decimal
(127)10 = ( 177 )8
(256)8 = (174)10
(225)10 = (341)8
= 64 + 56 + 7
= (127)10
(225)8 = (149)10
Egs:
1. (110011001)2 = (?)8
2. (10110011)2 = (?)8
3. (676)8 = (?)10
4. (987)10 = (?)8
Converting Octal to Binary
Eg 1: (227)8 = (?)2
1. 7 = 111
2. 2 = 010
3. 2 = 010
4. Final ans: (010010111)2
Eg 2: (5204)8 = (?)2
1. 4 = 100
2. 0 = 000
3. 2 = 010
4. 5 = 101
5. Final ans: (101010000100)2
Perform the following conversions
1. (335)10 = (517) 8
2. (1024)8 = (532) 10
3. (1101101101)2 = (1555)8
4. (101010101)2 = (341)10
5. (567)10 = (1000110111)2
6. (11011010100)2 = (3324)8
7. (7665)8 = (111110110101)2
8. (11011)10 = (25403)8
Hexadecimal Conversions
Base 16 (24)
0 to 15 digits
Eg: A5698BC
0 to 9, 10 – A, 11 – B, 12 – C, 13 – D, 14 –
E, 15 - F
Converting decimal number to hexadecimal
Divide the number by 16
(987654)10 = (F1206)16
(12457)10 = (30A9)16
Converting hexadecimal number to decimal
(D80)16 = (?) 10
D80 = 0*160 + 8*161 + D*162
= 0 + 128 + 13*162
= 128 +13*256
= 128 + 3328
= (3456)10
(1011101000110101)2 = (?)16
make grps of 4 from RHS, convert each grp to its equivalent decimal value,
0101 = 5 = 5
0011 = 3 = 3
1010 = 10 = A
1011 = 11 = B
(BA35)16
(100000110000011)2 = (4183)16
Binary Arithmetic
Binary addition
Subtraction
Multiplication
Division
Binary Addition
Rules
0+0=0
1+0=1
0+1=1
1 + 1 = 10
1 + 1 + 1 = 11
Solve
1. (15)10 + (10010)2 = (100001)2
2. (10010)2 + (135)8 = (1101111)2
3. (100011)2 + (1010101)2 = (?)10
4. (101000)2 + (11111111)2 = (?)2
Binary Subtraction
Rules
0–0=0
1–0=1
1–1=0
10 – 1 = 1
Solve
1. (11110)2 – (1101)2 = (10001)2
2. (110011)2 – (1100)2 = (100111)2
3. (100110)2 – (11001)2 = (1101)2
4. (110001)2 – (11001)2 = (11000)2
5. (1010101)2 – (101111)2 = (100110)2
Binary Multiplication
Rules
0*0=0
1*0=0
1*1=1
0*1=0
Solve
1. (1011)2 * (11)2 = (100001)2
2. (10101)2 * (10)2 = (101010)2
3. (101011)2 * (101)2 = (11010111)2
4. (111001)2 * (111)2 = (11000111)2
Binary Division
Rules
1÷1=1
0÷1=0
All rules of subtraction apply
Bring down digits in pairs
Solve
1. (101)2 ÷ (10)2 = (?)2 Q=10, R=1
101 –quotient – 10
10
001
Eg 3: (25.725)10 = (?)2
1. (25)10 = (11001)2
2. (0.725)10 = (0.1011100)2
0.725*2 = 1.45
0.45*2 = 0.9
0.9*2 = 1.8
0.8*2 = 1.6
0.6*2 = 1.2
0.2*2 = 0.4
0.4*2 = 0.8
3. (25.725)10 = (11001.1011100)2
Eg 4: (31.065)10 = (11111.00010)2
0.065*2 = 0.13
0.13*2 = 0.26
0.26*2 = 0.52
0.52*2 = 1.04
0.04*2 = 0.08
************THE END********