In: Computer Science
1 - Briefly describe overflow. When does it occur?
2 - Briefly describe underflow. When does it occur?
3 - What decimal number does the bit pattern 1101 1011 represent if it is a:
• unsigned integer?
• sign-magnitude integer?
• two's complement integer?
4 - What decimal number does the bit pattern 0011 1011 represent if it is a:
• unsigned integer?
• sign-magnitude integer?
• two's complement integer?
5 - What is the binary representation of the decimal number 28 assuming the IEE 754 single precision format?
6 - What decimal number does the bit pattern 0xBF800000 represent if it is:
• A two's complement integer?
• An unsigned integer?
• A floating point number assuming the IEE 754 single precision format
7 - Perform the following calculations assuming that the values are 4-bit decimal integers stored in two's complement format. Be sure to consider the possibility of overflow.
• 1101 + 0011
• 1101 – 0011
8 – For the following operations: write the operands as 2's complement binary numbers then perform the addition or subtraction operation shown. Show all work in binary operating on 4-bit numbers.
• 4 + 2
• 4 - 2
• 2 - 4
Answer 1:
An overflow is occurred when result would have more bits than the bits in original numbers.
The rules for detecting overflow in a two's complement sum are simple:
1. When we perform the sum of two positive/negative numbers the sum is exceed the range of the bit field of those two numbers.
2. If the operands have different (resp. identical) signs overflow cannot occur in addition (subtraction).
If we add two positive number 7 + 6 using 4-bit binary number, result should be +13
Carry |
1 |
1 |
||
(+7) |
0 |
1 |
1 |
1 |
(+6) + |
0 |
1 |
1 |
0 |
(-3) |
1 |
1 |
0 |
1 |
In signed notation, this is a result of -3, not +13, so overflow occurs
Answer 2:
An underflow is occurred when the result of a calculation is a number of smaller absolute value than the computer can actually store in memory
For example, an 8-bit computer is capable of storing unsigned integers ranging from 0–255. If result generated after performing any operation is less than 0 then an underflow is occur.
An underflow can occurs when the result of a after performing floating point operation is smaller than the smallest value representable.
If we add two positive number -120 and -9 using2’s complement number, result should be -129 which is the smallest possible value that we can represent by a 8-bit 2’s complement number (-128) so overflow occurs .
Carry |
|||||||||
(-120) |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
|
(-9) + |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
|
(-129) |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
Carry generated so discard it and take 2’s complement of result which 10000001(-129)
Answer 3:
i) Unsigned integer
Binary to Decimal Conversion
• Technique
– Multiply each bit by 2n, where n is the “weight” of the bit
– The weight is the position of the bit, starting from 0 on the right
– Add the results
i)Determine the Decimal equivalent of ( 1101 1011)2
Binary |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
1 |
Number |
||||||||
Weight of |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
Each Bit |
||||||||
Weighted |
1 X27 |
1 X26 |
0X25 |
1 X24 |
1 X23 |
0X22 |
1X21 |
1X 20 |
Value |
||||||||
Solved |
128 |
64 |
0 |
16 |
8 |
0 |
2 |
1 |
Multiplication |
||||||||
Sum of weight of all bits = 128+64+16+8+2+1=219
Answer: (1101 1011)2 = (219)10
ii) Signed integer
In case of Signed Number If MSB bit is 0 then number is Positive number and if it is 1 then number is negative number.
For given number MSB is 1 so number is negative and remaining bit give magnitude we can convert it into decimal by applying above method. Which is 91.
MSB (signed bit) |
Magnitude |
1 |
1011011 |
Answer: (1101 1011)2 = -(91)10
iii) Two's complement integer
In this case take 2’s complement of given number and convert into decimal using above method.
For 2’s complement take 1’s complement and then add 1 into it.1’s complement means change 0 into 1 and 1 into 0.
Given number |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
1 |
1’s complement |
0 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
Add 1 |
1 |
|||||||
Binary |
0 |
0 |
1 |
0 |
0 |
1 |
0 |
1 |
Decimal |
37 |
Answer: (1101 1011)2 = (37)10
Answer 4:
i) Unsigned integer
Binary to Decimal Conversion
Technique
– Multiply each bit by 2n, where n is the “weight” of the bit
– The weight is the position of the bit, starting from 0 on the right
– Add the results
i)Determine the Decimal equivalent of ( 0011 1011)2
Binary 0 0 1
1 1 0 1
1
Number
Weight of 27 26
25 24
23 22
21 20
Each Bit
Weighted 0 X27 0
X26 1X25 1
X24 1 X23
0X22 1X21 1X
20
Value
Solved 0 0 32
16 8 0 2
1
Multiplication
Sum of weight of all bits = 32+16+8+2+1=59
Answer: (0011 1011)2 = (59)10
ii) Signed integer
In case of Signed Number If MSB bit is 0 then number is Positive
number and if it is 1 then number is negative number.
For given number MSB is 0 so number is positive and remaining bit
give magnitude we can convert it into decimal by applying above
method. Which is 59.
MSB (signed bit) Magnitude
0 0111011
Answer: (0011 1011)2 = + (59)10
iii) Two's complement integer
In this case take 2’s complement of given number and convert into
decimal using above method.
For 2’s complement take 1’s complement and then add 1 into it.1’s
complement means change 0 into 1 and 1 into 0.
Given number 0 0 1
1 1 0 1
1
1’s complement 1 1
0 0 0 1
0 0
Add 1 1
Binary 1 1 0
0 0 1 0
1
Decimal 197
Answer: (0011 1011)2 = (197)10
Answer 5: The IEE 754 single precision format is given below,
Sign |
Exponent |
Mantissa |
1bit |
8bit |
23bit |
32bits |
Step-1: Find Binary equivalent
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc
Determine the Binary equivalent of (28)10
2 |
28 |
Remainder |
Least Significant Bit ( LSB) |
2 |
14 |
0 |
|
2 |
7 |
0 |
|
2 |
3 |
1 |
|
2 |
1 |
1 |
|
0 |
1 |
Most Significant Bit ( MSB) |
|
(28)10 = (11100)2
Step-2: Normalize the binary representation of the number.
28(10) =1 1100(2)
=1 1100(2) × 20
= 1.1100(2) × 24
Step-3: Adjust the exponent.
Adjusted Exponent (Biased exponent)
= 127+ Exponent (unadjusted)
= 127+4
= (131)10
Step-4: