You are on page 1of 28

Mekdela Amba University

Chapter Two
Number System and Codes

Topics covered:
Course outline and schedule
Introduction
Data Types

 Binary information is stored in memory or processor registers.


 Registers contain either data or control information.
 Data are numbers and other binary-coded information
 Control information is a bit or a group of bits used to
specify the sequence of command signals
 Data types found in the registers of digital computers
 Numbers used in arithmetic computations
 Letters of the alphabet used in data processing
 Other discrete symbols used for specific purpose
Number Systems
 Most common number system :Decimal, Binary, Octal,
Hexadecimal

2
Cont…

 Decimal number system is important because it is


universally used to represent quantities outside a digital
system. Decimal system uses numbers from 0 to 9. This is to
the base 10.
 Binary numbers are based on the concept of ON or OFF.
Binary number system has a base of 2. Its two digits are
denoted by 0 & 1 and are called bits.

3
Cont…

 Octal Number system uses exactly eight symbols


0,1,2,3,4,5,6, and 7. i.e., it has a base of 8. Each octal digit
has a unique 3 bit binary representation.
 Hexadecimal number system is to the base 16. It spans from
0 to 9 and then A to E. In hexadecimal system A,B,C,D,E and
F represents 10,11,12,13,14 and 15, i.e., it has a base of 16.
Hexadecimal numbers are more convenient for people to
recognize and interpret than the long strings of binary
numbers

4
Cont…

Decimal Binary Code Octal Hexadecimal


0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

5
Conversion Of Number System

 The right most bit is called Least Significant Bit (LSB) and
left Most Bit is called Most Significant Bit (MSB).
ie., 100111
MSB LSB
1. Conversion from Binary to Decimal
 The binary number system have a base 2, the position
weights are used on the power of 2.
Ex: 100111 = ?
1 x 25 + 0x 24 + 0x 23 + 1x22 + 1x21 + 1x20
1 x 32 + 0x 16 + 0x 8 + 1x4 + 1x2 + 1x1 = 39
100111 = 39  Ans.

6
Cont…

2. Conversion from Decimal to Binary


 The simplest way to convert a decimal number to a binary
number is by dividing the given number repeatedly by 2
until we get 0 as the quotient. Then, we write the
remainders in the reverse order to get the binary value of
the given decimal number.
Ex: 29 = ?

7
Cont…

3. Conversion from Decimal to Octal:


 In case of decimal to octal, we divide the number by 8 and
write the remainders in the reverse order to get the
equivalent octal number.
Example 1: Convert (127)10 to Octal.
Solution: Divide 127 by 8
127 ÷ 8= 15(Quotient) and (7)Remainder
 Divide 15 by 8 again.
15 ÷ 8 = 1(Quotient) and (7) Remainder
 Divide 1 by 8, we get;
1 ÷ 8 = 0(Quotient) and (1) Remainder
 Since the quotient is zero now, no more division can be done. So by
taking the remainders in reverse order, we get the equivalent octal
number.
 Hence, (127)10 = (177)8

8
Cont…

4. Conversion from Octal to Decimal:


 To convert an octal number to a decimal number we need
to multiply each digit of the given octal with the reducing
power of 8. Let us learn here, the conversion of Octal
number to Decimal Number or base 8 to base 10.
Example 1: Suppose 2158 is an octal number, then it’s decimal
form will be,
2158 = 2 × 82 + 1 × 81 + 5 × 80
          = 2 × 64+ 1 × 8 + 5 × 1 = 128 + 8 + 5
          =  14110
Example 2: Let 125 is an octal number denoted by 1258. Find
the decimal number.

9
Cont…

5. Conversion from Hexadecimal to Decimal:


 To convert an octal number to a decimal number we need
to multiply each digit of the given Hexadecimal number
with the reducing power of 16. Let us learn here, the
conversion of Hexadecimal number to Decimal Number or base
16 to base 10.
Ex: convert (2BD1)16 to base 10 number.

10
Con..

6. Octal to hexadecimal and Vise versa


 To convert from Octal to hexadecimal, first we have to
convert to binary and the binary to hexadecimal. To convert
from hexadecimal to Octal, first we have to convert to
binary and then the binary to Octal.
Example: Convert (235)8 to hexadecimal
2388 =010 011 101
=0000 1001 1101
=0 9 13
=(9D)16

11
Con…

7.Binary (base2) to Octal (base 8) or hexadecimal (base16)


and vice versa
To convert a number in binary to octal group three binary digits
together starting from the last digit (right) and if there are
no enough digits add zeros to the front end (left) and find the
corresponding Octal of each group.
Example1: Convert 1001001 to octal
1001001=001,001,001
= 1118
 Example2: Convert 111001111 to Hexadecimal
111001111 =0001 1100 1111
=1 12 15
=1 B F
=(1BF) 16

12
Con…

 To convert from Octal to binary, convert each octal digit to


its equivalent 3 bit binary starting from right.
Example: Convert (675)eight to binary
6758 =110 111 101
=(110111101)2
 To convert from Hexadecimal to binary convert each hex.
Digit to its equivalent 4-bit binary starting from right.
Example: Convert 23416 to binary
23416 =0010 0011 0100
= 10001101002

13
BINARY ARITHMETIC

 Computer understands only the language of binary numbers.


Therefore, the machine performs what is called binary arithmetic
(binary computation).
 Binary addition
Binary addition operates by the same rule as decimal addition, except
that it is simpler. A carry to the next higher order (or more
significant) position occurs when the sum is decimal 2, that is,
binary 10. Therefore, the binary addition rules may be written as
follows:
0+0=0
0+1=1
1+0=1
1+1=0 plus a carry of 1 into the next position
1+1+1=1 plus a carry of 1 into the next position.

14
Cont…

 The last case occurs when the two binary digits in a certain
position are 1s and there is a carry from the previous position.
Example1:
6+7 =13
110+111=1101
 Binary Subtraction
It operates by the same rule as decimal subtraction. The rule is as
follows;
0-0=0 1-0=1 1-1=0 10-1=1
Example:
11100 28 101101 45
- 11010 -26 - 111 -7
00010 =2 100110 =38

15
Cont…

 Binary Multiplication
 Multiplication in binary is similar to its decimal counterpart. Two
numbers A and B can be multiplied by partial products: for each
digit in B, the product of that digit in A is calculated and written
on a new line, shifted leftward so that its rightmost digit lines
up with the digit in B that was used. The sum of all these partial
products gives the final result.
 Since there are only two digits in binary, there are only two
possible outcomes of each partial multiplication:
• If the digit in B is 0, the partial product is also 0
• If the digit in B is 1, the partial product is equal to A
• For example, the binary numbers 1011 and 1010 are multiplied as
follows:

16
Representation Of Negative Numbers

 There are different ways of representing negative numbers in a


computer.
I. Sign- magnitude representation
In signed binary representation, the left-most bit is used to
indicate the sign of the number. Traditionally, 0 is used to
denote a positive number and 1 is used to denote a negative
number.
But the magnitude part will be the same for the negative
and positive values. For example, 11111111 represents-127
while, 01111111 represents + 127. We can now represent positive
and negative numbers, but we have reduced the maximum
magnitude of these numbers to 127.

17
1’s complement

 To get 1’s complement of a binary number each bit of the


binary number is subtracted from 1.
 The 1’s complement of 01 is 10. Thus we can see that the 1’s
complement of a binary number can be obtained by simply
changing each bit 1 to 0 and 0 to 1.
Ex1 : Find 1’s complement of 1100101
The 1’s complement is 0011010
Ex2: +2 is 00000010
-2 is 11111101
 Note that in this representation positive numbers start with a
0 on the left, and negative numbers start with a 1 on the left
most bit.

18
2’s Complement

 The 2’s complement of a binary number is equal to the 1’s


complement of the number plus one.

Ex: 11010 (2) =? 2’s complement


1’s complement of 11010 is 00101
+ 1
00110
11010 (2)= 00110 (2’s complement )

19
Coding Methods

 In today’s technology, the binary number system is used by the


computer system to represent the data in the computer in
understandable format. There are a lot of ways to represent,
numeric, alphabetic, and special characters in computer’s internal
storage area.
 There are different coding systems that convert one or more
character sets into computer codes. Some are: EBCDIC, BCD,
ASCII-7 & ASCII-8, etc.
 In these encodings, binary coding schemes separate the
characters, known as character set, in to zones. Zone groups
characters together so as to make the coding scheme to decipher
and the data easier to process. With in each zone, the individual
characters are identified by digit code.

20
Cont…

 EBCDIC: Pronounced as “Eb-see-dick” and stands for Extended


Binary Coded Decimal Interchange Code.
 It is an 8-bit coding scheme: (00000000 – 11111111), i.e. it uses 8
bits to represent each character. It accommodates to code 28 or
256 different characters. This provides a unique code for each
decimal value 0 to 9 , each upper and lower case English letter
(for total of 52), and for a variety of special characters.
 Since it is an 8-bit code, each group of the eight bits makes up
one alphabetic, numeric, or special character. It is a standard
coding scheme for the large computers.

21
Cont…

Character zone (4 Bit) digit (4 Bit)


0-9 15 0-9
a-i 8 1-9
j-r 9 1-9
s-z 10 2-9
A-I 12 1-9
J-R 13 1-9
S-Z 14 2-9

Example:
character Zone Digit

A 1100 0001

a 1000 0001

9 1111 1001

22
Cont…

BCD (Binary Coded Decimal)


There were two types of BCD coding techniques used before. The
4 bit BCD, which represent any digit of decimal number by four bits
of binary numbers. If you want to represent 219 using 4 bit BCD
you have to say 0010 0001 1001
4 bits BCD numbers are useful whenever decimal information is
transferred into or out of a digital system.
 Examples of BCD systems are electronic ousters, digital
voltmeter, and digital clocks; their circuits can work with
BCD numbers.
BCD’s are easy for conversion but slower for processing than
binary. And they have limited numbers because with BCD we can
represent only numbers 0000 for 0 and 1001 for 9.

23
Cont…

 BCD (6-bits): It uses 6-bits to code a Character (2 for zone bit


and 4 for digit bit) it can represent 26 = 64 characters (10 digits,
26 capital characters and some other special characters).
 Some Coding Examples:

Character zone (2 Bit) digit(4 Bit)


0-9 0 0-9
A-I 3 A-I

Example:

Character zone (2 Bit) digit(4 Bit)


A 11 0001
Q 10 1000
8 00 1000

24
Cont…

 ASCII-7 and ASCII-8


 ASCII stands for American Standard Code for Information
Interchange. ASCII-7 used widely before the introduction of
ASCII-8 (the Extended ASCII). It uses 7 bits to represent a
character. With the seven bits, 27( or 128) different
characters can be coded (0000000-1111111). It has 3 zone and 4
digit bits positions.
 Coding examples:

Charter zone (3 bit) digit(4 bit)


0-9 3 0-9
A-O 4 1-15
P-Z 5 1-10

25
Cont…

 The ASCII System

 Also referred as ASCII-8 or Extended ASCII. It is commonly


used in the transmission of data through data communication
and is used almost exclusively to represent data internally in
microcomputers. ASCII uses 8-bits to represent alphanumeric
characters (letters, digits and special symbols). With the 8-
bits, ASCII can represent 28 or 256 different characters
(00000000-11111111). It assigns 4 bits for the zone and the
rest for the digit.

26
Cont…
Character zone (4 BIT) digit (4 BIT)
0-9 3 0-9
A-O 4 1-15
P-Z 5 0-10
a-o 6 1-15
p-z 7 0-10
Example:
Character zone (4 BIT) digit (4 BIT)
a 0110 0-9
b 0110 1-15
A 0100 0-10
B 0100 1-15

27
The End!!

28

You might also like