This might be very basic or even silly to experts here but I wanted to get my head around this. Most of the times I generally write hex values like this in C:
unsigned int a = 0xFFFF1232;
Let's say I am trying to extract the first and last 16-bits then I can simply do:
unsigned short high = a >> 16; // Gives me 0xFFFF
unsigned short low = a & 0x0000FFFF; // Gives me 0x00001232 which is then stored as 0x1232
In some of the code I am reading I have come across the following:
unsigned short high = a >> 16;
unsigned short low = a & 0xFFFF;
I have two questions
AND
ing a 32-bit value with a mask, why do people write 0xFFFF
instead of 0x0000FFFF
? Is it to keep it compact? 0x0000FFFF
as 0xFFFF
? Is it interpreted differently in any context?The first nine numbers (0 to 9) are the same ones commonly used in the decimal system. The next six two-digit numbers (10 to 15) are represented by the letters A through F. This is how the hex system uses the numbers from 0 to 9 and the capital letters A to F to represent the equivalent decimal number.
The hexadecimal numeral system, often shortened to "hex", is a numeral system made up of 16 symbols (base 16). The standard numeral system is called decimal (base 10) and uses ten symbols: 0,1,2,3,4,5,6,7,8,9. Hexadecimal uses the decimal numbers and six extra symbols.
Memory addresses are displayed as two hex numbers. An example is C800:5. The part to the left of the colon (C800) is called the segment address, and the part to the right of the colon (5) is called the offset. The offset value can have as many as four hex digits.
They're completely synonymous. Leaving out the leading zeros makes it a little more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With