简体   繁体   English

表示8086中的-130的位数最少?

[英]Minimum no of bits to represent -130 in 8086?

I need to know the minimum numbers of bits needed to represent 130 and -130 in 8086. 我需要知道表示8086中的130-130所需的最小位数。

  • For 130 (usigned): This would be unsigned, so it's represented normally. 对于130(无符号):这将是无符号的,因此可以正常表示。 130 = 0x82 = 1000 0010b In this case the answer would be 8 bits 130 = 0x82 = 1000 0010b在这种情况下,答案将是8位
  • For -130 (signed): A negative number in 8086 is the second complement of the usigned number plus 1. So, first complement (not 0x82): 0111 1101b and plus 1 it would be 0111 1110b = 0x7E. 对于-130(带符号):8086中的负数是无符号数字加2的第二个补码。因此,第一个补码(不是0x82):0111 1101b加上1它将是0111 1110b = 0x7E。 In my oppinion you would need a minimum of just 7 bits to represent -130. 在我看来,您只需要最少 7位即可代表-130。 Is this right ? 这是正确的吗 ? If the number is negative, shouldn't be the last bit enabled to know that the sign is negative ? 如果数字是负数,难道不应该是知道该符号是负数的最后一位吗? This would require more than 7 bits. 这将需要超过7位。

If somebody knows the answer for sure, please let me know. 如果有人肯定知道答案,请告诉我。

When taking the two's complement of a number, you must 在取数字的二的补码时,您必须

  • place an infinite number of 0 bits to the left 在左边放置无限个0位
  • invert all the bits 反转所有位
  • add 1 加1
  • remove some of the infinite number of 1 bits, if desired 如果需要,请删除一些无限数量的1位

Let's apply this to the number -130. 让我们将其应用于数字-130。 The bit pattern for 130 is 130的位模式是

1000 0010

After placing an infinite number of 0's on the left it's 在左侧放置无穷多个0之后

0000 0000 1000 0010

OK, so eight is slightly less than infinity, but you get the idea. 好的,所以八比无穷大一点,但是你明白了。 Next invert to get 下一个反转得到

1111 1111 0111 1101

and add 1 to get 并加1得到

1111 1111 0111 1110

At this point you can remove some of the infinite 1's on the left, but you must keep at least one of them. 此时,您可以删除左侧的一些无限1,但必须至少保留其中一个。 So the shortest two's complement representation of -130 requires 9 bits. 因此,最短的二进制补码表示法-130需要9位。

1 0111 1110

If the question is what size register is needed on an x86 processor, then the answer is a 16-bit register. 如果问题是x86处理器上需要什么大小的寄存器,则答案是16位寄存器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM