Are hexadecimal numbers ever negative?

后端 未结 6 944
感情败类
感情败类 2021-02-14 09:39

Are hexadecimal numbers ever negative? If yes then how?
For binary you would have signed and unsigned.
How would one represent them in Hex? I need this

6条回答
  •  猫巷女王i
    2021-02-14 10:13

    The high bit of a number determines if it is negative. So for instance an int is 32 bits long, so if bit 31 is a 1 it is negative. Now how you display that value be it hexadecimal or decimal doesn't matter. so the hex values like

    0x80000000
    0x91345232
    0xA3432032
    0xBFF32042
    0xC33252DD
    0xE772341F
    0xFFFFFFFF
    

    are all negative, because the top bit is set to 1

           |
           v
    0x8 -> 1000
    0x9 -> 1001
    0xA -> 1010
    0xB -> 1011
    0xC -> 1100
    0xD -> 1101
    0xE -> 1110
    0xF -> 1111
    

提交回复
热议问题