CHAPTER THREE
Data Representation And Register & Microoperations
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
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.
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
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
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
Page 1 of 11
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.
Ex- 2: 0.1010 = ?
1 x 2-1 + 0x 2-2 + 1x 2-3 + 0x2-4
1x(1/2) + 0x(1/4) + 1x (1/8) + 0 x (1/16)
1x0.5 + 0x0.25 + 1x 0.125 + 0 x 0.0625
( 8 + 4 + 0 + 1) + (0.5 + 0 + 0. 125 + 0 ) = 13.625
0.1010 = 0.625 Ans.
Ex-3: 1101.1010 = ?
(1 x 23 + 1x 22 + 0x 21 + 1x20 ) + (1 x 2-1 + 0x 2-2 + 1x 2-3 + 0x2-4 )
(1 x 8 + 1x 4 + 0x 2 + 1x1) + (1x0.5 + 0x0.25 + 1x 0.125 + 0 x 0.0625 )
( 8 + 4 + 0 + 1) + (0.5 + 0 + 0. 125 + 0 ) = 13.625
1101.1010 = 13.625 Ans.
Conversion from Decimal to Binary
Ex: 15 = ?
2 15
2 7 - 1
2 3 -1
1 -1
15 = 1111 Ans
Ex 2: 0.625 = ?
0.625 x 2 = 1.25 0.25 with a carry of 1 (MSB)
0.25 x 2 = 0.50 0.50 with a carry of 0
0.50 x 2 = 1.00 0.00 with a carry of 1 (LSB)
0.625 = 0.101
Ex 2: 0.39 = ?
0.39 x 2 = 0.78 0.78 with a carry of 0
0.78 x 2 = 1.56 0.56 with a carry of 1
0.56 x 2 = 1.12 0.12 with a carry of 1
0.39 = 0.011
Note: in this example it is seen that the fraction has not become zero, and the will continue further. For
such a case an approximation is made. For this example, we may take the result up to 3 binary bits after
the binary point.
Page 2 of 11
Conversion from Decimal to Octal:
Ex: 3977 = ?
8 3977
8 497 -1
8 62 - 1
7 - 6
3977 = 7611 Ans
Ex 2: 0.39 = ?
0.39 x 8 = 3.12 0.12 with a carry of 3
0.12 x8 = 0.96 0.96 with a carry of 0
0.96 x 8 = 7.68 0.68 with a carry of 7
0.68 x 8 = 5.44 0.44 with a carry of 5
0.39 = 0.3075
Conversion from Octal to Decimal:
The binary number system has a base 8, the position weights are used on the power of 8.
Ex: 3077 = ?
3 x 83 + 0x 82 + 7x 81 + 7x80
3 x 512 + 0x 64 + 7x 8 + 7x1 = 1599
3077 = 1599 Ans.
Conversion from Binary to Octal :
Ex: 10011.11001 = ?
010 011 . 110 010
2 3 6 2
= 23.62
Conversion from Octal to Binary :
Ex2: 377.77
Ex1: 37
= 011 111 011 111 111 . 111 111
=011111
Conversion from Decimal to Hexadecimal:
Ex: 39 = ?
16 39 Ex:
2 -7
39 = 27 Ans
0.256 x 16 = 4.096 0.096 with a carry of 4
Ex: 256 = ?
16 256 0.096 x16 = 1.536 0.536 with a carry of 1
16 16 - 0
1 - 0 0.536 x 16 = 8.576 0.576 with a carry of 8
Page 3 of 11
256 = 100 Ans
Ex: 1723.256 = ?
16 1723
16 107 - 11
6 - 11
Conversion from Hexadecimal to Decimal:
The binary number system has a base 16, the position weights are used on the power of 16.
Ex: 39A = ?
3 x 162 + 9x 161 + Ax 160
3 x 256 + 9x 16 + Ax 1
3 x 256 + 9x 16 + 10x 1 = 922 ( i.e., decimal 10 for A Hex)
39A = 922 Ans.
Ex: 3A.2F = ?
3x 161 + Ax 160 . 2 X 16-1 + 15 X 16-2
=48+10 . (2/16) + ( 15 / 162)
= 58.1836
Conversion from Binary to Hexadecimal :
Ex: 11100101110111
=0011 1001 0111 0111
= 3 9 7 7
=3977
Ex: 110101001.0010110
=0001 1010 1001 . 0010 1100
=1 A 9 . 2 C
Conversion from Hexadecimal to Binary :
Ex: 39A
=0011 1001 1010
Octal Binary Hexadecimal:
7521 Octal
111 101 010 001 Binary
1111 0101 0001 Hexadecimal
Hexadecimal Octal:
CBAED Hexadecimal
C B A E D
1100 1011 1010 1110 1101
011 001 011 101 011 101 101
3 1 3 5 3 5 5
CBAED 3135355
Page 4 of 11
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.
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
Example2
19+31+10=60
10011 +11111+1010=111100
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
Representation Of Negative Numbers
There are different ways of representing negative numbers in a computer.
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.
In a 5- bit representation we use the first bit for sign and the remaining 4- bits for the magnitude. So
using this 5 bit representation the range of number that can be represented is from -15 (11111) to
15(01111)
In the binary number system there are two types of complements, 1’s complement and 2’s complement.
To represent a negative binary number 2’s complement is most widely used. To understand 1’s and 2’s
complement in the binary number system one should first undertstand 9’s and 10’s complements in the
decimal number system.
Page 5 of 11
9’complement:
To form the 9’s complement of decimal number each digit of a decimal number is subtracted from 9.
The result so obtained is known as 9’s complement of the number.
Ex: Find 9’s complement of decimal number 37(10)
Sol : 37(10) = 9’s complement ?
9’s complement of 37 is 99 – 37 = 62.
Like that…3977(10) = 9’s complement ?
9’s complement of 3977 is 9999 – 3977 = 6022.
10’s complement :
The 10’s complement of a decimal number is equal to the 9’s complement of the number plus 1.
10’s complement of 37 is 99 – 37 = 62 +1 = 63.
1’s complement
The 1’s complement of binary number is similar to 9’s complement in the decimal system. 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.
2’s Complement:
The 2’s complement of the binary system is similar to 10’s complement in the decimal system. Thus 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 )
Ex2: 0000 (2) = ? 2’s complement
1’s complement of 000 is 1111
1
10000
0000 => 1 0000 (here 1 is carry)
Page 6 of 11
Binary Subtraction using 2’s Complement:
The addition of 2’s complement of a number is equivalent to the subtraction of the number.
Example 1: Subtract 0010(2) from 0101(2) ie., subtract 2(10) from 5(10)
Ordinary binary subtraction
0101 = 5(10)
- 0010 = 2(10)
0011 = 3(10)
Subtracting using 2’s complement
The addition of 2’s complement of 0010 (2(10)) to 0101 (5(10)) is equal to subtraction of 0010 (2(10)) from
0101 (5(10))
1’s complement of 0010 = 1101
2’s complement of 0010 = 1101 + 1 = 1110
0101 the decimal number of 5(10)
+ 1110 +2’s complement of 2(10)
0011 3(10)
Floating-Point Representation
In this representation decimal numbers are represented with a fixed length format. In order not to
waste bits, the representation will normalize all the numbers. For example, 0.000123 wastes three
zeroes on the left before non -zero digits. These zeroes have no meaning except to indicate the position
of the Decimal point. Normalizing this number result in .123x10-3 .123 is the normalized mantissa; -3 is
the exponent. We have normalized this by eliminating all the meaningless zeroes to the left of the first
non-zero digit and by adjusting the exponent.
Ex1: 22.1 is normalized as .221x102.
The general form of floating point representation is Mx10E where M is the mantissa, and E is the
exponent. It can be seen that a normalized number is characterized by a mantissa less than 1 and greater
than or equal to.1 all cases when the number is not zero.
To represent floating numbers in the computer system it should be normalized after converting to binary
number representation system.
Ex2 111.01 is normalized as .11101x23.
The mantissa is 11101. The exponent is 3.
The general structure of floating point is
Sign Exponent Mantissa (significand)
In representing a number in floating point we use 1 bit for sing, some bits for exponent and the remaining
bit for mantissa.
Page 7 of 11
In floating point representation the exponent is represented by a biased exponent (Characteristics).
Biased exponent = true exponent + excess 2n-1, where n is the number of bits reserved for the exponent.
Ex1.
Represent –236.375 in floating point using 7 bit for exponent and 16 bit for mantissa.
First we have to change to normalized binary
i. e 234 = 11100010
0.375= 0.011
234.375 = 11100010.011 = 0.11100010011x28
true exponent = 8
excess 2 n-1 = 2 7-1= 26= 64
Biased exponent = 8+26 =>
8+64 = 72
= 100 1000 2
Therefore –234.375 is represented as
1 1001000
1110001001100000
Sign 7-bits 16 bits
Ex2. Represent 34.25 in floating point using 7 bit for exponent and 24 bits
for mantissa.
34.25 = 1000 10.0 12
The normalized form of 34.25 = .10001001x 26
True exponent = 6 2 n-1 = 2 7-1= 6+26 =6+64=70
70 = 10001102
Therefore, 34.25 is represented as
0 1000110
100010010000…..0
Fixed Point Representation
Positive Integers, including zero, can be represented as unsigned numbers. However, to represent
negative integers, we need a notation for negative values. In ordinary arithmetic, a negative number is
indicated by a minus sign and a positive number by a plus sign.
Because of hardware limitations, computers must represent everything with 1’s and 0’s, including the
sign of a number. As a consequence, it is customary to represent the sign with a bit placed in the
leftmost position of the number.
There are two ways of specifying the position of the binary point in a register by giving it a fixed position
or by employing a floating point representation. The fixed point method assumes that the binary pint is
always fixed in one position. The two positions most widely used are
Page 8 of 11
1) A binary point in the extreme left of the register to make the stored number a fraction, and
2) A binary point in the extreme right of the register to make the stored number an integer.
Representation of number as an integer:
When an integer binary number is positive, the sign is represented by 0 and the magnitude by a positive
binary number.
When the number is negative, the sign is represented by 1 but the rest of the number maybe
represented in one of three possible ways:
1. Signed magnitude representation
2. Signed 1’s complement representation
3. Signed 2’s complement representation
The negative number is represented in either the 1’s or 2’s complement of its positive value.
It’s customary to use 0 for the + sign and 1 for the –sign. Therefore -001, -010 and -011 are coded as
1001, 1010 and 1011.
Note: Complement
Sign –magnitude numbers are easy to understand, but they require too much hardware for addition and
subtraction. It has led to the widespread use of complements for binary arithmetic.
For instance, if A = 0111 The 1’s complement is Ā = 1000
The 2’s complement is defined as the new word obtained by adding 1 to 1’s complement. As an equation
A ‘ = Ā + 1 Where A ‘ = 2’s complement
Ā = 1’s complement
Here are some examples. If A = 0111
The 1’s complement is Ā = 1001
In terms of a binary the 2’s complement is the next reading after the 1’s complement.
Another example, If A = 0000 1000
Then Ā = 1111 0111
1 (adding 1)
And A ‘ = 1111 1000
Example: Consider the signed number 14 stored in an 8 bit register.
+14 is represented by a sign bit of 0 in the leftmost position followed by the binary equivalent of 14
00001110. Note that each of the eight bits of the register must have a value and, therefore, 0’s must be
inserted in the most significant positions following the sign bit.
Although there is only one way to represent +14, there are three different ways to represent -14 with
eight bits.
Sign bit
In signed magnitude representation 1 0001110
In signed 1’s complement representation 1 1110001
In signed 2’s complement representation 1 1110010
The signed magnitude representation of -14 is obtained from +14 by complementing only the sign bit.
The signed 1’s complement representation of -14 is obtained by complementing all the bits of +14,
including the sign bit.
The signed 2’s complement representation is obtained by taking the 2’s complement of the positive
number, including its sign bit.
Page 9 of 11
Arithmetic Addition:
The addition of two numbers in the signed-magnitude system follows the rules of ordinary
arithmetic. If the signs are same, we add the two magnitudes and give the sum the common sign. If the
sign are different, we subtract the smaller magnitude from the larger and give the result the sign of the
larger magnitude.
Add the two numbers, including their sign bits, and discard any carry out of the sign bit position.
Numerical examples for addition are shown below. Note that negative numbers must initially be in 2’s
complement and that if the sum obtained after the addition is negative, it is in 2’s complement form.
+6 00000110 -6 11111010
+13 00001101 +13 00001101
+19 00010011 +7 00000111
In each of the two cases, the operation performed is always addition, including the sign bits. Any carry
out of the sign bit position is discarded, and negative results are automatically in 2’s complement form.
Arithmetic subtraction:
Subtraction of two signed binary numbers when negative numbers are in 2’s complement form is
very simple.
The complement of a negative number in complement form produces the equivalent positive number.
Ex: (-6) – (-13) = +7
In binary with 8 bits this is written as 11111010 – 11110011.
The subtraction is changed to addition by taking the 2’s complement of (-13) to give (+13).
Ie., 11110011 2’s complement is 0000 1101
In binary this is 11111010 + 00001101 = 100000111.
Removing the end carry, we obtain the correct answer 00000111 (+7)
It is worth noting that binary numbers in the signed 2’s complement system are added and subtracted
by the same basic addition and subtraction rules as unsigned numbers.
Therefore, computers need only one common hardware circuit to handle both types of arithmetic.
Page 10 of 11
Overflow:
When two numbers of n digits each are added and the sum occupies n+1 digits, we say that an
overflow occurred.
An overflow is a problem in digital computers because the width of registers is finite.
A result that contains n+1 bits cannot be accommodated in a register with a standard length of n
bits. For this reason, many computers detect the occurrence of an overflow, and when it occurs, a
corresponding flip-flop is set which can then be checked by the user.
An overflow may occur if the two numbers added are both positive or both negative.
Example: Two signed binary numbers, +70 and +80, are stored in two 8bit registers.
carries : 0 1 carries: 1 0
+70 0 1000110 -70 1 0111010
+80 0 1010000 -80 1 0110000
+150 1 0010110 -150 0 1101010
Note that the 8 bit result that should have been positive has a negative sign bit and the 8bit result that
should have been negative has a positive sign bit. If, however, the carry out of the sign bit position is
taken as the sign bit of the result, the 9 bit answer so obtained will be correct.
Since the answer cannot be accommodated within 8 bits, we say that an overflow occurred. If the two
carries are applied to an exclusive-OR gate, an overflow will be detected when the output of the gate is
equal to 1.
Page 11 of 11