Are hexadecimal numbers ever negative?

后端 未结 6 935
感情败类
感情败类 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条回答
  •  伪装坚强ぢ
    2021-02-14 10:22

    Yes. For example you'd have the following representations in signed 32-bit binary and hex:

    Decimal: 1
     Binary: 00000000 00000000 00000000 00000001
        Hex: 00 00 00 01
    
    Decimal: -1
     Binary: 11111111 11111111 11111111 11111111
        Hex: FF FF FF FF
    
    Decimal: -2
     Binary: 11111111 11111111 11111111 11111110
        Hex: FF FF FF FE
    

    As you can see, the Hex representation of negative numbers is directly related to the binary representation.

提交回复
热议问题