UNIT-2 Computer Arithmatic
UNIT-2 Computer Arithmatic
at
Amity University Rajasthan
C0mputer Ar1+hmet1c
Dr. Kapil Kumar Nagwanshi
[email protected]
Arithmetic & Logic Unit
Everything else in
Does the the computer is
Handles integers
calculations there to service
this unit
Positive
numbers
stored in
Only have 0 & binary
No decimal Sign- Two’s
1 to represent No minus sign
• e.g. 41=00101001 point Magnitude compliment
everything
Sign-Magnitude
Problems
• Need to consider both
-18 = 10010010 sign and magnitude in
arithmetic
• Two representations
+18 = 00010010 of zero (+0 and -0)
1 means negative
0 means positive
One representation
of zero
Arithmetic works
easily (see later)
• 3 = 00000011
Negating is fairly • Boolean complement gives 11111100
easy • Add 1 to LSB 11111101
Negation (+18-18)
• Take the Boolean complement of each bit of integer (including
sign bit).
• Treating the result as an unsigned binary integer, add 1
• See Example
+18 0 0 0 1 0 0 1 0
Com 1 1 1 0 1 1 0 1
+ 1
Res 1 1 1 0 1 1 1 0 -18
Negation Special Case 1
• 0= 00000000
• Bitwise not 11111111
• Add 1 to LSB +1
• Result 1 00000000
• Overflow is ignored, so:
•-0=0
Negation Special Case 2
• -128 = 1000 0000
• bitwise not 0111 1111
• Add 1 to LSB +1
• Result 1000 0000
• So:
• -(-128) = -128 X (for n bit 2’s complement system there is only
representation for -2n not for +2n.
• Monitor MSB (sign bit)
• It should change during negation
Range of Numbers
• 8 bit 2s compliment
• +127 = 01111111 = 27 -1
• -128 = 10000000 = -27
• 16 bit 2s compliment
• +32767 = 011111111 11111111 = 215 - 1
• -32768 = 100000000 00000000 = -215
Conversion Between Lengths
• Positive number pack with leading zeros
• +18 = 00010010
• +18 = 00000000 00010010
• Negative numbers pack with leading ones
• -18 = 10010010
• -18 = 11111111 10010010
• i.e. pack with MSB (sign bit)
Addition
and
Subtractio
n Normal Monitor sign
binary bit for
addition overflow
Complex
Fixed? Moving?
• Very limited • How do you show
where it is?
Floating Point