Number Systems & Codes
Number Systems & Codes
Prepared by
Md. Asif Nashiry
Lecturer
Dept of CSE, JSTU.
[email protected]
Agenda
Understand different number systems
Understand how to convert numbers from one number system
to another.
Understand some alphanumeric codes.
Base (Radix) 10
Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
e.g. 747510
Base (Radix) 2
Digits 0, 1
e.g. 11102
1011 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20
Base (Radix) 8
Digits 0, 1, 2, 3, 4, 5, 6, 7
e.g. 16238
162 = 1 x 82 + 6 x 81 + 2 x 80
Base (Radix) 16
Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F
e.g. 2F4D 16
These patterns of "on" and "off" stored inside the computer are
used to encode numbers using the binary number system.
Because of their digital nature, a computer's electronics can
easily manipulate numbers stored in binary by treating 1 as "on"
and 0 as "off."
1. It is very difficult to program in machine language. The programmer has to know details
of hardware to write program.
2. The programmer has to remember a lot of codes to write a program which results in
program errors.
3. It is difficult to debug the program.
To overcome this limitation, octal and hexadecimal number systems were developed. Octal
& Hexadecimal are more compact than binary but are still based on the digital nature of
computers.
Dept. of CSE, JSTU. 16
Why Octal & Hexadecimal?
Hexadecimal number systems
Represent computer memory address
Ease of converting from binary and vice versa.
Represent various color codes used in computers
Used in programming language.
Decimal Octal
Binary Hexadecimal
Example:
Convert the decimal number 01102 into its decimal equivalent.
0 1 1 0
23 22 21 20
0110 2 = 6 10
8 4 2 1
0 + 4 + 2 + 0 = 610
Dept. of CSE, JSTU. 19
Binary to Decimal
Example:
Convert the binary number 01101012 into its decimal equivalent.
Solution:
0 1 1 0 1 0 1
26 25 24 23 22 21 20
64 32 16 8 4 2 1
0 + 32 + 16 + 0 + 4 + 0 + 1 = 5310
\01101012 = 5310
Basic Principle:
Multiply each bit by 8n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Example:
Convert the octal number (724)8 into its decimal equivalent.
7 x 82 + 2 x 81 + 4 x 80 = 46810
Example:
Convert the Hexadecimal number (ABC)16 into its decimal equivalent.
Example
Convert the decimal number 610 into its binary equivalent.
3
2 6 r 0 Least Significant Bit
1
2 3 r 1
0 610 = 1102
2 1 r 1 Most Significant Bit
23
Dept. of CSE, JSTU.
Decimal to Binary
Example: (125)10 = (?)2
2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Dept. of CSE, JSTU. 24
Decimal to Octal
Basic Principle
Divide by 8
Keep track of the remainder
8 1234
8 154 2
8 19 2
8 2 3
0 2
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Dept. of CSE, JSTU. 28
Binary to Octal
Basic Principle
Group bits in threes, starting on right
Convert to octal digits
1 3 2 7
10110101112 = 13278
Dept. of CSE, JSTU. 29
Octal to Binary
Basic Principle
Convert each octal digit to a 3-bit equivalent binary representation
1 0 A F
10AF16 = 00010000101011112
Dept. of CSE, JSTU. 31
Binary to Hexadecimal
Basic Principles
Group bits in fours, starting on right
Convert to hexadecimal digits
2 B B
10101110112 = 2BB16
Dept. of CSE, JSTU. 32
Octal to Hexadecimal & Vice Versa
Basic Principle
Use binary as an intermediary
Hexa-
Decimal Binary Octal decimal
33 ? ? ?
? 1110101 ? ?
? ? 703 ?
? ? ? 1AF
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Binary to decimal
(10.1011)2 = (?)10
= 2.6875
(10.1011)2 = (2.6875)10
Dept. of CSE, JSTU. 36
Dealing with fractions
Decimal to Binary
.14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Dept. of CSE, JSTU. 37
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
7 0 9 3
16-bit code
Support international language
Thank you
Md. Asif Nashiry
Lecturer
Dept. of CSE
Jessore Science & Technology University
Jessore 7408, Bangladesh.
[email protected]
46