A byte long as an 8-bit computer, number of machines known integer variables x, y, respectively
Fill [x]=11110000
[y] fill=10111000
Z=4 * x + y/2
The z machine number is?
Answer to overflow, I calculate not overflow, could you tell me how to calculate?
CodePudding user response:
4 * x=1
1 00 0000//the sign bit is 1, that is negative, retain the sign bit, left two (low fill 0)
Y/2=1
1 01, 1100//the sign bit is 1, keep the sign bit, moves to the right one (high fill 1)
Together, as a result, the
1 1001, 1100, the overflow, you only need to look at the sign bit of two operands are all followed by one of the 1, will be able to determine whether it will overflow the
CodePudding user response:
Depends on how much its integer length, if only 1 byte, affirmation overflow
CodePudding user response:
reference 1st floor qybao response: 4 * x=1 1 00 0000//the sign bit is 1, that is negative, retain the sign bit, left two (low fill 0) Y/2=1 1 01, 1100//the sign bit is 1, keep the sign bit, moves to the right one (high fill 1) Together, as a result, the 1 1001, 1100, the overflow, you only need to look at the sign bit of two operands are all followed by one of the 1, will be able to determine whether will overflow the Bosses, y/2 I calculate different Should not be the fill (y) to calculate the y=11001000 Y/2=10100100 CodePudding user response:
X said - 16 Y - 72 Z=4 * x + y/2 =4 * (16) + (72)/2 =- 100. 4 * x=1100, 0000//the sign bit is 1, that is negative, retain the sign bit, left two (low fill 0) - 64 Y/2=1101, 1100//the sign bit is 1, keep the sign bit, moves to the right one (high fill 1) - 36 Together, as a result, 1 1001 1100 despite overflow, but take its low 8, said 1001, 1100-100, the results are correct, CodePudding user response:
quoted zhao 4, 4/f, the teacher's reply: x said - 16 Y - 72 Z=4 * x + y/2 =4 * (16) + (72)/2 =- 100. 4 * x=1100, 0000//the sign bit is 1, that is negative, retain the sign bit, left two (low fill 0) - 64 Y/2=1101, 1100//the sign bit is 1, keep the sign bit, moves to the right one (high fill 1) - 36 Together, as a result, 1 1001 1100 despite overflow, but take its low 8, said 1001, 1100-100, the results are correct, Teacher, I dizzy Eight plastic range 128 to 127, isn't it - 100 zha overflow CodePudding user response:
A bit of a problem, there is no clear is signed or unsigned CodePudding user response:
Overflow is to have the number of symbols, unsigned number is carry/borrow CodePudding user response:
The refer to fifth floor I was so afraid QAQ response: teacher, I dizzy Eight plastic range 128 to 127, isn't it - 100 zha overflow? Overflow should be is not to say, to determine the scope of because of its overflow, so to ensure its value in the range also For example, 0 x7fffffff (a maximum of four int) + 1=0 x80000000 (negative) The negative is also in the range of 0 x80000000 x7fffffff 0, it is not overflow? CodePudding user response:
On the fourth floor of the four teachers have proved vivid, overflow and error are two different things, overflow error is not necessarily associated with, Think back to when I was eight years old, spilling a tooth, too normal, CodePudding user response:
refer to the eighth floor qybao response: Quote: I was so afraid QAQ reference 5 floor response: Teacher, I dizzy Eight plastic range 128 to 127, isn't it - 100 zha overflow? Overflow should be is not to say, to determine the scope of because of its overflow, so to ensure its value in the range also For example, 0 x7fffffff (a maximum of four int) + 1=0 x80000000 (negative) The negative is also in the range of 0 x80000000 x7fffffff 0, it is not overflow? Understand, should use the judging and complement overflow I direct the original code and the Is that there is no overflow,,, CodePudding user response:
Thank you,