This is basically the same as saying subtract 1 from 0x01000000 and results in the value 0x0FFFFFF basically hexadecimal is base 16, it often uses the following symbols:
Hexdec | Decimal
:–|:–
0|0
1|1
2|2
3|3
4|4
5|5
6|6
7|7
8|8
9|9
A|10
B|11
C|12
D|13
E|14
F|15
And so when you add -1 to 0x1000000 you get 0x0FFFFFF. It gets a little annoying to learn arithmetic in hexadecimal but it is easier than other bases.
If you think about hexadecimal like decimal, you count `0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F` which is equal to `0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15`
Like decimal math, if you take 1 away from 0, there must be a digit in the next place to “give” the lower place a value.
So decimal math, `100 – 1`. `0-1` forces to borrow 1 from the 10s place and then again from the 100s place, making `99`.
Similarly, `x100 – 1`. `0-1` forces 1st digit to borrow from the 2nd digit and, since the 2nd place is 0, again from the 3rd. Instead of becoming `9`, those places become the highest value of hex, making `x0FF`
Now apply that to your problem. `x1000000 – 1 = x0FFFFFF`
You know how you count in decimal, when you get to 9 you add 1 to the next place over start back at 0. With hexadecimal, you keep counting A B C D E F before carrying over to the next place and starting back at zero.
It’s just a more convenient way of displaying data for lots of computer based operations. The maximum value an unsigned integer can store is just “F” in every place.
>add 0x1000000 – 1
Lets say a computer is adding two four byte signed integers, that would be 0x01000000, and -1 in decimal would be represented as 0xFFFFFFFF. (in computers, negative numbers are represented in twos complement). The way this works out is that you can still add the numbers normally.
01 00 00 00
FF FF FF FF
——————————-
1 00 FF FF FF
The 1 at the left sets the carry flag, but in this case that’s just ignored, leaving a result of 0x00FFFFFF.
Going back the other way, if you add 1 to the 0x00FFFFFF, you carry several times and end up with 0x01000000.
Latest Answers