0% found this document useful (0 votes)
13 views46 pages

Number Systems & Codes

Uploaded by

Daring Hunterz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views46 pages

Number Systems & Codes

Uploaded by

Daring Hunterz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 46

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.

Dept. of CSE, JSTU. 2


Basic Definition
Number System: The way of representing numbers is called number system.

There are four number systems.


 Decimal
 Binary
 Octal
 Hexadecimal

Base/Radix: The total number of unique digits/components in a particular


number system is called the base or radix of that number system.
For example
The base of decimal number system is 10 since it has 10 (ten) unique digits
from 0 to 9. With these ten digits we can form any number.

Dept. of CSE, JSTU. 3


Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F

Dept. of CSE, JSTU. 4


Decimal System

Base (Radix) 10
Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
e.g. 747510

7475 = 7 x 1000 + 4 x 100 + 7 x 10 + 5 x 1


7 x 103 + 4 x 102 + 7 x 101 + 5 x 100

Dept. of CSE, JSTU. 5


Take a look: Decimal numbers
0 19 100
1 20 101
2 21 102
3 22 .
4 23 .
5 . 109
6 . 110
7 30 111
8 31 .
9 . .
10 . 999
11 90 1000
12 . 1001
13 .
. .
. 99

Dept. of CSE, JSTU. 6


Binary System

Base (Radix) 2
Digits 0, 1
e.g. 11102

1011 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20

Dept. of CSE, JSTU. 7


Take a look: Binary numbers
Binary Numbers Decimal Equivalent
0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
. .
. .
. .
. .

Dept. of CSE, JSTU. 8


Octal Number

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

Dept. of CSE, JSTU. 9


Take a look: Octal numbers
Octal Decimal Octal Decimal
0 0 21 17
1 1 22 18
2 2 23 19
3 3 . .
4 4 27 23
5 5 30 24
6 6 31 25
7 7 .
10 8 77 63
11 9 100 64
12 10 101 65
13 11 102 66
14 12 . .
. 777 511
17 15 1000 512
20 16
Dept. of CSE, JSTU. 10
Hexadecimal System

Base (Radix) 16
Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F
e.g. 2F4D 16

2F4D = 2 x 163 + F x 162 + 4 x 161 + D x 160

Dept. of CSE, JSTU. 11


Take a look: Hexadecimal numbers
Hexadecimal Decimal Hexadecimal Decimal
0 0 11 17
1 1 12 18
2 2 13 19
3 3 .
4 4 19 25
5 5 1A 26
6 6 1B 27
7 7 . .
8 8 1F 31
9 9 20 32
A 10 21 33
B 11 . .
C 12 2F 47
D 13 30 48
E 14 . .
F 15 FF 255
10 16 100 256
Dept. of CSE, JSTU. 12
Some more basic definition
 Bit: Bit is for binary digit. Each binary digit is called a bit.
So, 0 and 1 are called bits.

 Byte: A group of eight bits is called a byte/octet.


hence 1 byte = 8 bits.

 Nibble: A nibble is a four-bit aggregation or half


an byte/octet.

 Word: A group of bits is called a word.

Dept. of CSE, JSTU. 13


Why Binary number system?
How Computers Store Numbers
Computer systems are constructed of digital electronics. That means that their
electronic circuits can exist in only one of two states: on or off. Most
computer electronics use voltage levels to indicate their present state. For
example,
 A transistor with five volts would be considered "on", while a transistor
with no voltage would be considered "off.”
 CD-ROM's, for example, use microscopic dark spots on the surface of the
disk to indicate "off," while the ordinary shiny surface is considered "on.“
 Hard disks use magnetism, while computer memory uses electric charges
stored in tiny capacitors to indicate "on" or "off.“

Dept. of CSE, JSTU. 14


Why Binary number system?

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."

Dept. of CSE, JSTU. 15


Why Octal & Hexadecimal?
Binary is an effective number system for computers because it is easy to implement with
digital electronics. It is inefficient for humans to use binary, however, because it requires so
many digits to represent a number. The number 76, for example, takes only two digits to
write in decimal, yet takes seven digits to write in binary (1001100).
The only advantage of binary system is that program of machine language run very fast
because no translation program is required for the CPU.
However following are the disadvantages:

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.

 Octal number systems


 Ease to convert from binary and vice-versa.
 Octal is sometimes used in computing instead of hexadecimal, perhaps most often in
modern times in conjunction with file permission under Unix systems. It has the advantage of
not requiring any extra symbols as digits (the hexadecimal system is base-16 and therefore
needs six additional symbols beyond 0–9).
 Octal numbers that are used in some programming languages (C, Perl, Postscripts…) for
textual/graphical representations

Dept. of CSE, JSTU. 17


Conversion Among Bases
The possibilities

Decimal Octal

Binary Hexadecimal

For example, 2510 = 110012 = 318 = 1916


Dept. of CSE, JSTU. 18
Binary to Decimal
 Basic Principle
 Multiply each bit by 2n, 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 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

Dept. of CSE, JSTU. 20


Octal to Decimal

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

Dept. of CSE, JSTU. 21


Hexadecimal to Decimal
 Basic Principle:
 Multiply each bit by 16n, 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 Hexadecimal number (ABC)16 into its decimal equivalent.

A x 162 + B x 161 + C x 160


=
10 x 256 + 11 x 16 + 12 x 1
= 2560+176+12
= 274810
Dept. of CSE, JSTU. 22
Decimal to Binary
 Basic Principle
 Divide by two, keep track of the remainder
 Divide the Decimal Number by 2; the remainder is the LSB of Binary
Number .
 If the quotation is zero, the conversion is complete; else repeat step (a)
using the quotation as the Decimal Number. The new remainder is the
next most significant bit of the Binary Number.

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

Dept. of CSE, JSTU. 25


Decimal to Octal

Example: 123410 = (?)8

8 1234
8 154 2
8 19 2
8 2 3
0 2

Dept. of CSE, JSTU.


 123410 = 23228 26
Decimal to Hexadecimal
 Basic Principles
 Divide by 16
 Keep track of the remainder

Dept. of CSE, JSTU. 27


Decimal to Hexadecimal

 Example: (1234)10 = (?)16

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

Example: 10110101112 = (?)8

1 011 010 111

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

Example: 7058 = (?)2


7 0 5

111 000 101

Dept. of CSE, JSTU.


 7058 = 1110001012 30
Hexadecimal to Binary
 Basic Principle
 Convert each hexadecimal digit to a 4-bit equivalent binary
representation
Example: 10AF16 = (?)2

1 0 A F

0001 0000 1010 1111

 10AF16 = 00010000101011112
Dept. of CSE, JSTU. 31
Binary to Hexadecimal
 Basic Principles
 Group bits in fours, starting on right
 Convert to hexadecimal digits

Example: 10101110112 = (?)16


10 1011 1011

2 B B

 10101110112 = 2BB16
Dept. of CSE, JSTU. 32
Octal to Hexadecimal & Vice Versa

 Basic Principle
 Use binary as an intermediary

Dept. of CSE, JSTU. 33


Exercise – Convert ...

Hexa-
Decimal Binary Octal decimal
33 ? ? ?
? 1110101 ? ?
? ? 703 ?
? ? ? 1AF

Don’t use a calculator!

Dept. of CSE, JSTU. 34


Exercise – Convert ...
Answer

Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF

Dept. of CSE, JSTU. 35


Dealing with fractions

 Binary to decimal

(10.1011)2 = (?)10

1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3 + 1 x 2-4

= 2.0 + 0.0 + 0.5 + 0.0 + 0.125 + 0.0625

= 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

Don’t use a calculator!

Dept. of CSE, JSTU. 38


Exercise – Convert ...
Answer

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

Dept. of CSE, JSTU. 39


Computer Codes
Data: Data is a collection of facts, such as values or measurements.
It can be numbers, words, measurements, observations or even just
descriptions of things.

Information: information is processed data. i.e. information is data


which have been converted into a more useful form.

Code: Code means the representation of data and/or information in


a format suitable for further use. By coding:
volume of data reduced
recording of data may be less laborious
less prone to error
data become more manageable and easier to manipulate.

Dept. of CSE, JSTU. 40


BCD Code (8-4-2-1 code)

 Four bits per digit Digit Bit pattern


0 0000
Note: the following bit 1 0001
patterns are not used:
2 0010
1010
1011 3 0011
1100 4 0100
1101
1110 5 0101
1111 6 0110
7 0111
8 1000
9 1001
Dept. of CSE, JSTU. 41
Example

 709310 = ? (in BCD)

7 0 9 3

0111 0000 1001 0011

Dept. of CSE, JSTU. 42


ASCII Code
 Each character is coded as a byte
 Most common coding system is ASCII (Pronounced ass-key)
 ASCII = American Standard Code for Information
Interchange
 Popular in data communication
 Used in microcomputer
 Two types
 ASCII 7
▪ 7 bits code, allow 27 different characters
▪ First 3 bits as zone bits and last 4 bits indicate the digits
 ASCII 8
▪ 8 bits code, allow 28 different characters
▪ Use 7-bit ASCII, the additional bit is added to zone bits.

Dept. of CSE, JSTU. 43


EBCDIC code
 Extended BCD Interchange Code (pronounced ebb’-se-dick)
 8-bit code
 Developed by IBM
 Rarely used today
 IBM mainframes only

Dept. of CSE, JSTU. 44


Unicode
ASCII & EBCDIC codes fail to effectively represent so many
characters of some international language.

 16-bit code
 Support international language

Dept. of CSE, JSTU. 45


That’s All

Thank you
Md. Asif Nashiry
Lecturer
Dept. of CSE
Jessore Science & Technology University
Jessore 7408, Bangladesh.
[email protected]
46

You might also like