Title: Fixedpoint Representation of Numbers
1Fixed-point Representation of Numbers
2Fixed Point Representation of Numbers
- Sign-and-magnitude representation
- Twos complement representation
- Twos complement binary arithmetic
- Excess code representation
- Binary fractions
- Fixed point representation of fractional numbers
3Sign-and-magnitude representation
- magnitude of a number
- the numerical value of the no. excluding its sign
- the sign-and-magnitude method
- the leftmost bit represent the sign of the no.
- the remaining bits represent the binary
equivalent of the magnitude of the no. - sign bit - the bit represents the sign of a no.
4ExampleExpress 3710 and -1410 in 8-bit binary
codes using the sign-and-magnitude method
- convert the magnitude of the nos. into binary
- 3710 1001012
- 1410 11102
- if necessary, add 0s at the left until 7 binary
digits - 3710 1001012 01001012
- 1410 11102 00011102
- add a 0 or 1 at the left according to the
sign of the no. - 3710 001001012
- - 1410 100011102
5Pros Cons of sign-and-magnitude method
- Advantages
- simple and easy to understand
- Disadvantages
- the no. zero can be represented in two ways
- 00000000 and 10000000
- the sign bit and the magnitude part have to be
handled separately complicates the design of
the circuit used for addition particularly
6Twos complement representation
- counters of some cassette recorders and most
video cassette recorders (0000 - 9999) - reset the counter to 0000
- rewind a tape
- the counter changes to 9999 decreases gradually
- similar to the design of the memory of a computer
(00000000 - 11111111)
7Twos Compl.
- the leftmost bit of the binary code
- a ve no. ? 0
- a -ve no. ? 1
- the range of nos. represented is -128 to 127
- 11111111 1 00000000
- 01111111 1 10000000
8The relation between a no. its negative
- The codes 01111110 (126) 100000010 (-126) are
called the twos complement of each other -
- it can be obtained by
- changing all 0s to 1s and all 1s to 0s
- adding the resulting binary code by 1
9Example Obtain the twos complement of 00101110
and 10100010
- 00101110
- change to 11010001
- 11010001 1 11010010
- 10100010
- change to 01011101
- 01011101 1 01011110
-
10To convert a denary no. into an n-bit binary code
using the twos complement notation
- convert the magnitude of the denary no. into a
binary no. - add 0s at the left until it contains n digits
- if the original no. is negative, obtain the twos
complement of the binary code - (Note that we need not find the twos complement
if the original no. is non-negative)
11Examplerepresent 3710 and -1410 in 8-bit twos
complement code
- 3710 1001012 001001012
- 1410 11102 000011102
- -1410 111100012 1 111100102
12To convert a 8-bit binary code back to its
denary equivalent
- if the leftmost bit is 0 (i.e. the no. is ve)
- treat it as a simple binary no. and convert it
into denary - if the leftmost bit is 1 (i.e. the no. is -ve)
- obtain its magnitude by finding its twos
complement - change it to a denary no. and add the sign - in
front of it
13Advantages of twos complement representation
- electronic circuit used is very simple in design
- no separate circuit is needed for subtraction
- no separate circuit is needed to handle the sign
bit and the magnitude part - each no. is represented by a unique code
- avoid ambiguity and widens the range of no.
represented
14Twos complement binary arithmetic
- Addition
- Subtraction
- Overflow
- all nos. are represented in twos complement
notation, and the no. of bits of each binary code
is fixed
15Addition
- addition is done in usual binary nos.
- if a carry occurs beyond the leftmost bit, it is
discarded - Example perform the following additions in twos
complement binary arithmetic using 8-bit binary
codes - 60 41
- (-60) (-41)
- 60 (-41)
1660 41
- Check Denary equivalent
- 60
- ) 41
- 101
- Carry ? 111
- 00111100
- ) 00101001
- 01100101
- Ans. 01100101
17(-60) (-41)
- Check Denary equivalent
- -60
- ) -40
- -101
- carry ? 11 1
- 11000100
- ) 11010111
- 110011011
- The extra digit is discarded
- ans. 10011011
1860 (-41)
- Check Denary equivalent
- 60
- ) - 40
- 19
- Carry ? 111111
- 00111100
- ) 11010111
- 100010011
-
- The extra digit is discarded
- ans. 00010011
19Subtraction
- Since x - y x (-y),
- x - y is found by adding x to the twos
complement of y. - Example perform the following additions in twos
complement binary arithmetic using 8-bit binary
codes - 60 - 41 60 (-41)
- 60 - (-41) 60 41
- (-60) - (-41) (-60) 41
20Overflow
- overflow is said to occur when at some stage
during processing binary arithmetic, a no.
outside the finite range is generated - for 8-bit binary codes in twos complement form,
the finite range is -12810 to 12710 - concentrate on the possible occurrence of
overflow during addition only - when two nos. to be added are of the same sign,
overflow may occur
21To find 86 60
- Carry ? 11111
- 01010110
- ) 00111100
- 10010010
-
- Check Denary equivalent
- 86
- ) 60
- 146
The answer is 10010010, whose denary equivalent
is -110 i.e, overflow has occurred.
22Conclusion of Overflow
- In most microcomputers, 16-bit (or even 32-bit)
binary codes are used - the range becomes -32768 to 32767 inclusively
- However, no matter how many bits we use, it is
still possible to find nos. outside the finite
range
23Binary fractions
- denary nos.
- 1 2 . 6 2 5
- place value 101 100 10-1 10-2
10-3 - decimal point
- binary fraction
- 1 0 . 0 1 1
- place value 21 20 2-1 2-2
2-3 - binary point
24- 10.0112
- 21 2-2 2-3
- 2 1/4 1/8
- 2.37510
- 12.62510
- 12 0.625
- 12 5/8
- 12 1/2 1/8
- 11002 0.12 0.0012
- 1100.1012
25Fixed point representation of fractional numbers