Professional Documents
Culture Documents
UNIT5POSITIVENUMBERS
UNIT5POSITIVENUMBERS
Negative numbers inside the computer is represented by the two’s complement. Two’s complement
of a binary number is the complement of the number plus one. The complement of 1 is 0 and the
complement of 0 is 1. The complement of a binary number is calculated by complementing each bit
of the number.
1
If the result produces a carry, discard the carry and the result is positive.
If the result does not produce a carry, take two’s complement of the result, and the
result is negative.
Example 4 Subtract B = 101010 from A = 110101.
01010 1 = Complement of B
Two’s complement of B = 010101 + 1 = 010110
Add two’s complement of B to A.
110101
+ 010110
----------------
10 01011
Carry, discard the carry and the result is +001011.
As we can see, adding two 6-bit number results in a 6-bit answer. There is no
carry; we just take the two’s complement of the result.
Two’s Complement of 110101 = 001010 + 1 = -001011
IV. Unsigned, Signed Magnitude, and Signed Two’s Complement Binary Number
A binary number can be represented in form unsigned number or signed number or signed two’s
complement, + sign represented by 0 and – sign represented by 1.
1. Unsigned Number
In an unsigned number, all bits of a number are used to represent the number, but in a signed
number, the most significant bit of the number represents the sign. A 1 in the most significant
position of number represents a negative sign, and 0 in the most significant position of number
represents a positive sign.
The 1101 unsigned value is 13.
In a binary number, the first bit from the left of number is called the most significant bit (MSb), and
the first bit from the right of number is called least significant bit (LSb).
MSb →1 0 0 1 0← LSb
2
3. Signed Two’s Complement
A signed two’s complement applies to a negative number. If the sign of the number is one, then the
number is represented by signed two’s complement.
11011010
+ 00101100
----------------
100000110 discard the carry and result is 00000110=6
3
-44 = 11010100
------------
10101110= -82
Addition Overflow The following cases result overflow for adding two signed numbers if:
(a) Both numbers are negative, and results of addition become positive:
(-A) + (-B) =+C
(b) Both numbers are positive, and results of addition become negative:
(+A) + (+B) = -C
Floating Point Representation
The central processing unit (CPU) typically consists of an arithmetic logic unit (ALU), floating
point unit (FLU/FPU), registers, control unit, and the cache memory. The arithmetic logic unit
performs integer arithmetic operations such as addition, subtraction, and logic operations such as
AND, OR, XOR, etc. Integers are whole numbers without fractional components. 1, 2, and 3 are
integers, while 0.1, 2.2, and 3.0001 all have fractional components are called floating point
numbers.
The floating point unit performs floating point operations. Floating point numbers have a sign, a
mantissa, and an exponent. The Institute of Electrical and Electronics Engineers (IEEE) developed a
standard to represent floating point numbers, referred to as IEEE 754. This standard defines a
format for both single
(32-bit) and double (64-bit) precision floating point numbers. Decimal floating points are
represented by Mx10E, where M is the signed mantissa and E is the exponent.
Single Precision Representation
Floating point numbers in single precision represented by 32 bits as shown in the following
Figure
Fig. IEEE 745 floating point single precision (S = represent sign of mantissa. S =0 means mantissa
is positive, and S = 1 means mantissa is negative)
Biased Exponent The biased exponent is the exponent + 127 (01111111)2; therefore, the exponent
is represented by a positive number.
Normalized Mantissa The mantissa is represented by 1. M, where M is called normalized
mantissa; if M = 00101, then mantissa is 1.00101.
Example Find normalized mantissa and biased exponent of (111.0000111)2.
111.0000111 can be written in the form of 1.110000111 x 210
4
Where
M = 110000111
Biased exponent = 10 + 01111111 = 10000001
The representation of 111.0000111 in single precision is
Example Convert the following single precision floating point to decimal number.
101111101 11001000000000000000000
S = 1 means mantissa is negative. Biased exponent = 01111101.
Exponent = 01111101–01111111 = -00000010.
Normalized mantissa = 11001000000000000000000.
Mantissa =1. 11001000000000000000000.
Decimal number = 1.11001000000000000000000 x2-10 = 0.01110011.
Double Precision. In order to increase the accuracy of a floating point number, IEEE 745 offers
double precision represented by 64 bits as shown in the following Figure.
Biased exponent = exponent + 1023
5
Example Converting 345 to BCD Using the table: 0011 0100 0101
Example Convert (10100010010)BCD to decimal, separate each 4 bits from right to left, and
substitute the corresponding decimal number with BCD the results in 512.
Exercises
1. Find two’s complements of the following numbers:
(a) 11111111
(b) 10110000
(c) 10000000
(d) 00000000
2. Represent (465)10 in BCD.
3. Represent (100101100111)BCD in decimal.
4. Represent (110010000100)BCD in decimal.
5. Convert the following two’s complement numbers to decimal:
(a) 1011
(b) 11111001
(c) 10011111
6. Subtract the following unsigned numbers using two’s complement:
(a) 11110011–11000011
(b) 10001101–11111000
7. Perform addition of the following signed numbers; assume each number is
represented by 6 bits and state if the result of each addition produces overflow:
(a) (+12) + (+7)
(b) (+25) + (+30)
(c) (-5) + (+9)
(d) (-6) + (-7)
(e) (-36) + (-12)
8. What is the largest 16-bit binary value that can be represented by:
(a) Unsigned number
(b) Signed magnitude
(c) Signed two’s complement
9. Represent each of the following numbers in 8-bit signed two’s complement:
(a) -15
(b) -24
(c) -8
Represent the following decimal numbers in IEEE 745 single precision:
(a) 34.375
(b) -0.045
Convert the following IEEE 745 single precision to decimal number:
(a) 1 10000100 01110000000000000000000
(b) 0 01111100 11100000000000000000000