An integer overflow is the condition that occurs when the result of an arithmeti
ID: 3725172 • Letter: A
Question
An integer overflow is the condition that occurs when the result of an arithmetic operation, such as multiplication or addition, exceeds the maximum size of the integer type used to store it. If the integer in question is incremented past the maximum possible value, it may wrap to become a very small, or negative number, therefore providing a very incorrect value. It is often a critical security flaw in software.
For example, in a 16-bit integer system, 19458*37=64586. The result is supposed to be 719946, but has more than 16 bits. Therefore, the result is wrapped, i.e. only the least significant 16 bits of the result remain. Consider in a 32-bit integer system,
(3) Find "X" that satisfies the following equations. X > 1337 X * 7 + 4 = 1337
Explanation / Answer
Here for 16 bit integer system, 719946 binary representation is 10101111110001001010 and 64586 binary representation is 1111110001001010 . Clearly all the bits after 16 places gets truncated in the result when an overflow occurs.
Assuming same behaviour for 32-bit integer system, the solution is below:
1337 binary representation is 10100111001 .
1337's 32 bit binary representation is 0000 0000 0000 0000 0000 0101 0011 1001
Now ,since X > 1337 , so 7*X + 4 > 1337 .But the answer for (7*X + 4) = 1337
This implies, (7*X + 4) binary representation has more than 32 bits and thus those bits after 32 places get truncated and the answer shows only 32 bits which is 1337.
Our target is to calculate the truncated part.
Now 7*X = (1333)10 = (0000 0000 0000 0000 0000 0101 0011 0101)2
Now our target is to get the number X > 1337 which when multiplied by 7 then the result has the first 32 bits as
(0000 0000 0000 0000 0000 0101 0011 0101)2 which is (1333)10 .
Here,for X = (613566947)10
7*X = (4294968629)10 = (1 0000 0000 0000 0000 0000 0101 0011 0101)2
and thus the bits after 32 places gets truncated and the result obtained is (0000 0000 0000 0000 0000 0101 0011 0101)2 = (1333)10
So value of X > 1337 that satisfies X * 7 + 4 = 1337 is 613566947 .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.