Lecture 1
Lecture 1
Data Representation ::
Data Representation
Base conversion
For convenience, people use other bases (like decimal,
hexadecimal) and we need to know how to convert from one to
another.
Number systems
There are more than one way to express a number in binary. So
1010 could be -2, -5 or -6 and need to know which one.
Number representation
? +400
2000 ? +90
? + 3? = 2493
?
Decimal/ denary Number System
If we were to write out the digits of the denary number
“145.25”, what is the value of each digit?
Power of 10
representation
100 ? + ? 5 + 0.2
? + 40 ? + 0.05 ?
? = 145.25
Any Base → Denary
Now suppose we had a number in base 5 instead. How
do we convert it to denary?
In base 10, the place values
53 52 51 50 were powers of 10, i.e. 1,
10, 100, 1000. So in base 5,
we’d have powers of 5,
?
125 ?
25 5? 1? always starting with 1 on
the right.
4 3 0 15
4x53 3x52? 0x51 1x50
? + 0? + 1? = 576?
? + 75
500
Test Your Understanding
Convert the following to denary
8 4 ?2 1 64 16 ? 4 1
1 0 1 12 3 3 0 24
8 + 0 + ?2 + 1 = 11 192 + 48 + 0? + 2 = 242
27 9 ? 3 1
1 2 2 03
27 + 18 ?+ 6 + 0 = 51
Convert decimal to binary
Convert 56 to binary Convert 99 to binary
Binary
Quotient Remainder
99 ÷ 2 = 49 1
49 ÷ 2 = 24 1
24 ÷ 2 = 12 0
12 ÷ 2 = 6 0
6÷2 = 3 0
3÷2 = 1 0
1÷2 = 0 1
5610=1110002 9910=11000012
Convert decimal to octal
Convert 56 to octal Convert 99 to octal
Binary
Quotient Remainder
99 ÷ 8 = 12 3
12 ÷ 8 = 1 4
• nybble = 4 bits
• byte = 8 bits
Power of 2
27 26 25 24 23 22 21 20
representation
Decimal
128 64 32 16 8 4 2 1
representation
Base 2
1 0 1 0 1 1 1 0
representation
128 + 32 + 8 + 4 + 2 = 174
101011102 = 174
Convert Binary Decimal
Convert the binary number 10101110 to octal
a) 11 à3
b) 101 à5
c) 110 à6
d) 1111 à 15
e) 11011 à 27
Octal Number System
92 = 1348
Convert decimal to octal
Convert the binary number 1010.11 to octal
Power of 2
23 22 21 20 2-1 2-2
representation
Decimal
8 4 2 1 0.5 0.25
representation
Base 2
1 0 1 0 1 1
representation
a) 21 à 17
b) 156 à 110
c) 270 à 184
d) 1164 à 628
e) 2105 à 1093
Hexadecimal Number System
• The Hexadecimal number system, popularly known as Hex system
has 16 symbols, therefore its base/radix in 16.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
7 = 7
C = 12
F = 15
1 = 1
D = 13
A = 10
6 = 6
E = 14
8 = 8
B = 11
a) 2A à 42
b) 15F à 351
c) A7C à 2684
d) 11BE à 4542
e) A10D à 41229
Convert Hex to Decimal
Convert binary 11011 to hexa
Binary à decimal à hexa
Binary à decimal
(11011)2 = ?16
1 x 24 +1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = (27)10
Decimal à hexa
Decimal
Quotient Remainder
27 ÷ 16 = 1 11
1 ÷ 16 = 0 1
1, 11 = 1B
Convert Hex to Decimal
Convert hexa A59C to decimal
Hexa à decimal
Hexadecimal to Denary
Multiples
of 16:
Convert the following from
0: 0
hexadecimal to denary:
1: 16 (a) 34 (b) A3
2: 32
3: 48
4: 64
5: 80 16 1 16 1
6: 96
7:
8:
9:
112
128
144
3 4
?a 10 ?3b
A:
B:
160
176 48 +4 = 52 160 +3 = 163
C: 192
D: 208
E: 224
F: 240
Test Your Understanding
Multiples
of 16:
Convert 8C from hexadecimal to
0: 0
denary.
1: 16
2: 32
3:
4:
48
64
16 1
5:
6:
7:
80
96
112
8 12?
8:
9:
A:
128
144
160
128 +12 = 140
B: 176
C: 192
D: 208
E: 224
F: 240
Denary to Hexadecimal
We can use exactly the same method as we did for denary to
Multiples any general base…
of 16:
Convert 183 from denary to hexadecimal.
0: 0
1: 16
2: 32
3: 48 16 1
4: 64
5:
6:
80
96
B? 7?
7: 112
8:
9:
128
144
176 + 7 = 183
A: 160
B: 176
C: 192 What is the most number of 16s we can use to make
D: 208 up 183? The table on the left will be very handy!
E: 224
F: 240
Test Your Understanding
Multiples Convert 78 from denary Convert 234 from denary
of 16: to hexadecimal. to hexadecimal.
0: 0
1: 16 16 1 16 1
2: 32
3:
4:
48
64 4 ? E E ? A
5: 80
6:
7:
96
112
64 + 14 =84 224 + 10 =234
8: 128
9: 144
A: 160
B: 176
C: 192
D: 208
E: 224
F: 240
Hexadecimal to Binary
We already have methods to convert from denary to other bases, and other
bases to denary. We could therefore convert via denary.
5 10 ?
80 + 10 = 90
Then convert from denary to binary:
64 32 16 8 4 2 1
1 0 1 1 ?0 1 0
64 +16+8 +2 = 90
Hexadecimal to Binary
Convert 5A from hexadecimal to binary.
But a nice little trick to convert each digit separately (noting that each
hexadecimal digit requires 4 bits, i.e. a nibble), and then to concatenate the
results together.
5 in binary à 0101 ?
A = 10 in binary à 1010 ?
B = 11 in binary à 1011 ?
9 in binary à 1001 ?
Therefore B9 in binary ?
à 10111001
Test Your Understanding
Convert 6F from hexadecimal to binary.
6 in binary à 0110 ?
F in binary à 1111 ?
Therefore 6F in binary ?
à 01101111
Binary Addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (Carry 1)
Conversion between bases
To convert from one base to another:
10.7510 = 12.68
Conversion between bases
Convert 5 6. 8 9 10 to octal (base 8)
0.8910 : 0.70753412…8
12 10 15 14
0.322510 : 0.516
Reading remainders in reverse: CAFE16
202/16 = 12 R 10
12/16 =0 R 12
12 10 15 14 0.322510 : 0.516
11.7510 to binary
9.62510 to binary
62.510 to octal
106.4510 to octal
36.812510 to hexadecimal
3162.562510 to hexadecimal
Test Your Understanding
11.7510 to binary
11.7510 = 1011.112
Test Your Understanding
9.62510 to binary
9.62510 = 1001.1012
Test Your Understanding
62.510 to octal
9.62510 = 76.48
Test Your Understanding
106.4510 to octal
36.812510 = 24.D16
Test Your Understanding
3162.562510 to hexadecimal
3162.562510 = C5A.916
Binary Addition-Example
1 1 0 1 0 1
1 0 1 1 1 1
1 1 0 0 1 0 0
Binary Addition-Example
1 0 1 1 0
0 1 1 0 1
1 0 0 0 1 1
Adding in binary
1 0 0 1
+ 1 1 0 1
1
?e 0
?d 1
?c 1
?b 0
?a
1 1
Further Example
1 0 1 0
+ 1 1 0 1 1
1 0
?f ?e 0
?d 1
?c 0
?b 1
?a
1 1
Test Your Understanding
1 1 0 1
+ 1 1 1
1 0 1? 0 0
1 0 0 1
+ 1 0 1 1
1 0 1? 0 0
Review
1 Convert 71 from denary to binary 2 Add the binary numbers:
11010 + 1111
64 32 16 8 4 2 1
1 1 0 1 0
1 0 0
?
0 1 0 1
+ ? 1 1 1 1
1 0 1 0 0 1