Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are hexadecimal numbers ever negative?

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 for a hex routine I am about to embark upon.

like image 810
phoenix Avatar asked Apr 29 '11 01:04

phoenix


People also ask

How do you know if a hexadecimal is negative?

The hexadecimal value of a negative decimal number can be obtained starting from the binary value of that decimal number positive value. The binary value needs to be negated and then, to add 1. The result (converted to hex) represents the hex value of the respective negative decimal number.

How do you convert a negative hexadecimal to decimal?

now we know that your number is -0x1A8 . now you have to add up the digits multiplied with their place value. 8 * 16^0 + A (which is 10) * 16^1 + 1 * 16^2 = 424. So the decimal value of your number is -424.

What is a valid hexadecimal number?

Hexadecimal System Hexadecimal is the name of the numbering system that is base 16. This system, therefore, has numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and 15.

Which alphabet is not allowed in hexadecimal number system?

Hexadecimal uses the decimal numbers and six extra symbols. There are no numerical symbols that represent values greater than nine, so letters taken from the English alphabet are used, specifically A, B, C, D, E and F.


3 Answers

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
like image 147
MeBigFatGuy Avatar answered Oct 19 '22 22:10

MeBigFatGuy


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.

like image 25
Andrew Cooper Avatar answered Oct 19 '22 23:10

Andrew Cooper


Yes they can be. It's the same as binary as to how you interpret it (signed vs unsigned).

like image 24
Bala R Avatar answered Oct 19 '22 21:10

Bala R