Chapter 3
Chapter 3
Chapter 3
Complements
2 types of complements for base ‘ r’ system: r’s complement and (r-1)’s complement
( r - l )'s Complement
Given a number N in base r having n digits, the (r - 1)'s complement of N is
defined as (rn - 1) - N.
r’ s complement
Example 1:
Decimal number system: r=10. So (r-1)=9. Two types of complements are 9’s and 10’s
complements.
Let N=546700 in decimal number system. Find 9’s and 10’s complement.
Example 2:
Binary number system: r=2. So (r-1)=1. Two types of complements are 1’s and 2’s
complements.
Let N=1011001 in binary number system. Find 1’s and 2’s complement.
Binary addition
A B Sum=A+B Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Binary Subtraction
A B Sub=A-B Borro
w
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
0-1=> If we take a borrow(1) from the previous bit, then 10-1=1 in binary (10=2 in decimal,1 is 1
in decimal, 2-1=1 of decimal=1 in binary)
1’s complement of a number N can be obtained using 2 methods:
(a) Subtract each bit of N from 1.
N=1011001. 1’s complement: 0100110
(b) Interchange 0’s and 1’s bits of N.
N=1011001. 1’s complement: 0100110
2’s complement of a number N can be obtained by computing 1’s complement of N and adding 1 to it.
Integer representation
2 types of integer values: unsigned (all positive integers), signed (positive and negative numbers)
Signed integers: MSB=0 (+ve positive integer), MSB=1(-ve integer)
Let the binary number be 0101111 consisting of N=7 bits. Here Least Significant Bit
(LSB)=1 placed at 0th position. Most Significant Bit (MSB)=0 placed at 6th position.
Positive number has sign bit=0 at MSB and negative number has sign bit=1 at MSB.
14=1110 binary
+14 0 0001110
-14 has 3 representations:
signed magnitude form : complement sign bit of +14=1 0001110
1’s complement form: find 1’s complement of +14 including sign bit = 11110001
2’s complement form: find 2’s complement of +14 including sign bit = 11110010
+0= 0 0000000
-0 has 3 representations
signed magnitude form:1 0000000
1’s complement form: 1 1111111
2’s complement form: 1 00000000 =00000000
Since the number is stored in 8 bits, therefore 1 will be ignored. 2’s complement of -0=00000000
+0 and -0 have same representations in 2’s complement whereas they have different representations in
1’s complement and sign magnitude form.
Arithmetic Addition
form
+5 +( +7)
+5 + (-7)
-5 + (+7)
-5 + (-7)
+5= 00000101
+7=00000111
Solve +5 + (-7)
+5=00000101
-7=11111001
Solve -5 + (+7)
-5=11111011
+7=00000111
-5+(+7)=00000010
Solve -5 + (-7)
-5=11111011
-7=11111001
Note: 2’s complement of a binary number +N= -N and similarly 2’s complement of a binary
number
-N= +N
Arithmetic Subtraction
Subtraction of two signed binary numbers when negative numbers are in 2's complement
form can be stated as follows:
Take the 2's complement of the subtrahend B (including the sign bit)
Add it to minuend A (including the sign bit).
If carry then discard
If no carry then answer is negative and in 2’s complement form
+A – (+B) = +A + (-B)
+A – (-B)= +A + (+B)
-A –(+B)= -A + (-B)
-A –(-B) = -A + (+B)
Overflow
In CPU, there is a status register which stores values such as carry bit, sign bit, overflow
bit etc.
When two unsigned numbers are added, an overflow is detected from the end carry
out of the most significant position.
When two signed numbers are added, the sign bit is treated as part of the number
and the end carry does not indicate an overflow.
An overflow may occur if the two numbers added are both positive or both negative.
Overflow detection
If the carry into sign bit and carry out of sign bit are not equal, then overflow
occurs.
8 bit register: range +127 to -128 (0 to 127 & -1 to -128)
BCD addition
Arithmetic operations:
Disadvantages:
Wastage of considerable amount of storage space since the number of bits needed to
store a decimal number in a binary code is greater than the number of bits needed
for its equivalent binary representation.
the circuits required to perform decimal arithmetic are more complex.
Advantages
Some applications, such as business data processing, require small amounts of
arithmetic computations compared to the amount required for input and output of
decimal data.
eliminates the need for conversion to binary and back to decimal.
BCD addition
(31)r=(40)10
Verify: (31)13=(40)10
Question
Find the largest and smallest binary integers that can be expressed with N bits in the
following representations:
(a) unsigned representation
(b) signed magnitude representation
(c) signed 1’s complement representation
(d) signed 2’s complement representation
largest smallest
unsigned 2N - 1 0
signed magnitude +2 (N-1) - 1 -(2 (N-1) – 1)
signed 1’s complement +2 (N-1) - 1 -(2 (N-1) – 1)
signed 2’s complement +2 (N-1) - 1 -2 (N-1)
Examples:
largest smallest
N=2 N=4 N=8 N=2 N=4 N=8
unsigned 3 15 255 0 0 0
signed magnitude +1 +7 +127 -1 -7 -127
signed 1’s complement +1 +7 +127 -1 -7 -127
signed 2’s complement +1 +7 +127 -2 -8 -128
Range of values in binary number system
In addition to the sign, a number may have a binary (or decimal) point. The position of the
binary point is needed to represent fractions, integers, or mixed integer-fraction numbers.
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 point is always fixed in one position. The
two positions most widely used are
(1) a binary point in the extreme left of the register to make the stored number a
fraction
(2) a binary point in the extreme right of the register to make the stored number an
integer.
In either case, the binary point is not actually present, but its presence is assumed from the
fact that the number stored in the register is treated as a fraction or as an integer.
256.75=25675x10-2
256.75=.25675x103
The floating-point representation uses a second register to store a number that designates
the position of the decimal point in the first register.
+1001.11
Two main standard forms of floating point numbers are from IEEE (Institute of Electrical
and Electronic Engineers) and ANSI (American National Standards Institute)
organizations.
Byte1 : SEEEEEEE
S: sign bit of Mantissa
E: exponent bits (negative power is represented in 2’s complement form)
Byte2, Byte3, Byte4 for mantissa
Mantissa is in signed magnitude form.
Format is
SEEEEEEE MMMMMMMM MMMMMMMM MMMMMMMM
↑
assumed binary point
examples
(a) 13=(1101)2 = 0.1101 x 2 +4
Un-normalized form:
M=0 0000111 E=0110 => 0.0000111 x 2+6 = 0.0000111 x 1000000=>000011.1
= (3.5)10
Find the largest positive and smallest positive floating point number in un-normalized and
normalized form that can be stored in 4 bit mantissa and 4 bit exponent excluding zero.
Numbers in the mantissa and exponent are in signed-magnitude representation.
3-19. A 36-bit floating-point binary number has eight bits plus sign for the exponent and 26
bits plus sign for the mantissa. The mantissa is a normalized fraction. Numbers in the
mantissa and exponent are in signed-magnitude representation. What are the largest and
smallest positive quantities that can be represented, excluding zero?