简体   繁体   中英

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.

  • For 130 (usigned): This would be unsigned, so it's represented normally. 130 = 0x82 = 1000 0010b In this case the answer would be 8 bits
  • 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. In my oppinion you would need a minimum of just 7 bits to represent -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.

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
  • invert all the bits
  • add 1
  • remove some of the infinite number of 1 bits, if desired

Let's apply this to the number -130. The bit pattern for 130 is

1000 0010

After placing an infinite number of 0's on the left it's

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

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. So the shortest two's complement representation of -130 requires 9 bits.

1 0111 1110

If the question is what size register is needed on an x86 processor, then the answer is a 16-bit register.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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