decimal to negative hex?
Author |
Message |
registration
|
Posted: Tue Jul 06, 2010 3:06 pm Post subject: decimal to negative hex? |
|
|
can someone please explain the whole process in detail? (i read somewhere you add 2^32 and then convert to hex.. but then doesn't that mean each hexadecimal number has 2 decimal answers?) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Tue Jul 06, 2010 4:46 pm Post subject: RE:decimal to negative hex? |
|
|
Negative numbers are stored on most computers with a system called [url=http://en.wikipedia.org/wiki/Two's_complement]Two's Complement[/url]. This means that the "values" of the "low" 31 bits in a 32-bit integer are positive, with values 1, 2, 4, 8, 16, 32, etc, while the "high" bit is negative, with value -(2^31). In this system, -1 is all bits on: 1111111111...; the lowest negative number is 10000000... and the highest positive number is 01111111111...
You can do similar things with longer data types, such as having the low 63 bits be positive and the high bit having value -(2^63). This is commonly referred to as "long", though definitions may vary depending on your language of choice.
It is also possible to interpret the high bit as having a positive value. This is done in the case of unsigned integers. An unsigned integer can represent a higher maximum number, but cannot ever represent negative numbers. The lowest number is 0 (000000000...) and the highest number is 2^32-1 (1111111111...)
In this sense, you can consider any given hexadecimal value to have two different interpretations - one signed, one unsigned. There are other possible ways to encode numbers in hexadecimal, but this is the most common method. |
|
|
|
|
![](images/spacer.gif) |
|
|