Computer Organization
Lecture 8: Number System
Hafiz Muhammad Azeem Akram
School of Computer Science and Mathematics
Faculty of Engineering and Technology
[email protected] Outline
• Overview
• Number Systems
• Binary numbers
• Number Conversions
• Decimal to Binary
• Binary to Decimal
Number Systems
Number Systems are used in Computers
to represent the information. Number
systems have different bases and the
most common of them are the decimal,
binary, and hexadecimal.
Number Systems
Binary Numbers
Number Systems
Decimal Numbers
Number Systems
Hexadecimal Numbers
Byte 1 Byte 2
0 1 2 3 4 5 6 7 8 9 AB CD E F
Number Systems
Number Systems
Generic Rule
For a number of any Base N
There are N Digits: 0, 1, 2, 3, 4, 5, …, N-1
Nn-1 … N3 N2 N1 No
dn-1 … d3 d2 d1 do
Digit do is the least significant digit (LSD).
Digit dn-1 is the most significant digit (MSD)
Example – Decimal Number
The representation of the number 375 means 3 lots of a
hundred, plus 7 lots of ten plus 5 lots of 1:
100’s 10’s 1’s
3 7 5 = 375
Example – Decimal Number
Each column is the previous column risen to the
power of 10, e.g.,
1,000’s 100’s 10’s 1’s
2 4 5 6 = 2,456
or in other words: 2 x 1,000 + 4 x 100 + 5 x 10 + 6 x 1 = 2,456
Example – Decimal Number
All decimal numbers are represented by columns
of powers of 10:
… 10000 1000 100 10 1
… 104 103 102 101 100
Binary Numbers
• Binary is in concept exactly the same as Decimal.
• The units column is capable of storing values up to the
base (2) - 1. Therefore, the maximum number of units in
binary is 1.
• Like base 10, the column values are raised to the power of
the number base (i.e., 2), so the units columns are:
Binary Numbers
For 16-bit binary numbers, the columns will be
last bit
32,768 16,384 8192 4096 2048 1024 512 256
128 64 32 16 8 4 2 1
first bit
Example – Binary Number
• Examples of binary number representations:
10002 = 1 x 8 + 0 x 4 + 0 x 2 + 0 x 1 = 810
10112 = 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 = 1110
Number base
Counting in Binary
• Because the Binary uses base 2 as opposed to the
Decimal base 10, the numbers get larger (longer)
much more quickly, but they still obey the same
principles in terms of columns.
• In Decimal, the number “Ten” is represented by
10 (one 10s and no 1s)
• In Binary, the number “Ten” is represented by
1010 (one 8s, no 4s, one 2s and no 1s).
Decimal to Binary Conversion
To convert from Decimal to Binary, we divide the
Decimal number by the Binary base (i.e. 2) and
record the remainder. This process is repeated
until the number is 0 and then the final remainder
is recorded.
Decimal to Binary Conversion
57/2 = 28 remainder is 1
Converting 5710 to Binary
28/2 = 14 remainder is 0
14/2 = 7 remainder is 0
7/2 = 3 remainder is 1
3/2 = 1 remainder is 1
1/2 = 0 remainder is 1 Continue until the result is zero
The binary equivalent is the remainders read from the bottom to
the top, i.e., 5710 = 1110012
Decimal to Binary Conversion
Converting 20710 to Binary
207/2 = 103 remainder is 1
103/2 = 51 remainder is 1
51/2 = 25 remainder is 1
25/2 = 12 remainder is 1
12/2 = 6 remainder is 0
6/2 = 3 remainder is 0
3/2 = 1 remainder is 1
1/2 = 0 remainder is 1
The binary representation is the remainders read from the bottom
to top. So, 20710 = 110011112
Binary to Decimal Conversion
There are two ways of doing this conversion
1. Positional Method
2. Doubling Method
Binary to Decimal Conversion
Positional Method
In the positional method, we sum the
values according to their positions
Binary to Decimal Conversion
Example 1: Positional Method
To convert the binary string 100112 to decimal, we write out the
relevant columns and put the binary string underneath. Then, we add
together the columns where the 1’s are located.
Units 16 8 4 2 1
Binary 1 0 0 1 1
In this case, the 1’s are located under the units columns of 16, 2 and 1.
We add these together to get 16+2+1 = 19. So, 100112 is equal to 1910
Binary to Decimal Conversion
Example 2: Positional Method
Converting 1010011012 to decimal
Units 256 128 64 32 16 8 4 2 1
Binary 1 0 1 0 0 1 1 0 1
There are 1’s at units 256, 64, 8, 4 and 1. By adding these
numbers together, we get 256 + 64 + 8 + 4 +1 = 33310.
So, 1010011012 = 33310
Binary to Decimal Conversion
Although the positional method is a safe method to
use (i.e., less risk of error), it can become difficult as
the length of the binary number increases. For
example, 1101011101101111010101101012
Binary to Decimal Conversion
Doubling Method
• Convenient for large binary numbers
• Starting with the left-most digit of the given binary number,
for each digit as you move to the right, double the previous
total and add the current digit (Note: the initial total is zero).
Binary to Decimal Conversion
Example 1: Doubling Method
To convert the binary string 10012 to decimal:
(So, 10012 = 910)
Binary to Decimal Conversion
Example 2: Doubling Method
1 0 1 0 0 1 1 0 1
1 2
2 4
5 10
10 20
20 40
41 82
83 166
166 332
333
Binary to Decimal Conversion
Doubling Method
Attention
Higher risk of error: Mistakes could
be made when you move from left
to right.
Next lecture
• Continuation of Number Systems
• Hexadecimal Numbers
• Numbers Conversion