Interpreting signed and unsigned numbers

ぐ巨炮叔叔 提交于 2019-12-02 09:15:02

A signed and an unsigned number have exactly the same bits!

In your calculator, you can display as hex (0xff). It's up to you whether you want to interpret the hex digits and "signed" or "unsigned".

In x86 assembler, you can check the "sign bit" in the CPU status flags.

Check out this tutorial:

Signed vs Unsigned Numbers

Unsigned numbers are the easiest to interpret from binary; simply add all the values that the bits represent (2^7+2^0 in the case of the number 1000 0001 =129).

The signed interpretation is pretty much the same, except for one extra step first: If the leading digit is 1, then you invert all the bits (in this case 0111 1110) and add 1 to the result to get the (absolute) value of the negative number (in this case 0111 1111=127)

To test that you did it correctly, do the same operation again and you should end up with the original number.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!