Will this:
((0x10203040 >> 24) & 0xFF) == 0x10
always be TRUE on both little-endian and big-endian machines?
Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first, at the lowest storage address. Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.
The advantages of Little Endian are: It's easy to read the value in a variety of type sizes. For example, the variable A = 0x13 in 64-bit value in memory at the address B will be 1300 0000 0000 0000 . A will always be read as 19 regardless of using 8, 16, 32, 64-bit reads.
The same is true for a four-byte value; for example, 0x12345678 would be stored as (0x12 0x34 0x56 0x78). Little endian means that the least significant byte of any multi-byte data field is stored at the lowest memory address. This means a Hex word like 0x1234 is stored in memory as (0x34 0x12).
The benefit of little endianness is that a variable can be read as any length using the same address. One benefit of big-endian is that you can read 16-bit and 32-bit values as most humans do; from left to right.
Yes. Endianness only affects how bytes are stored in memory. The value of 0x10203040
is always 270544960
regardless of whether it's the first or last byte in memory that is the 0x10
.
To gratuitously borrow images from the Wikipedia article on Endianness, regardless of which of these layouts our system uses:
the value of 0x0A0B0C0D
is still the same.
will this:
((0x10203040 >> 24) & 0xFF) == 0x10
be always TRUE on both little-endian and big-endian machines?
Yes, it will provide the same result on both architectures. It's actually a mathematical operation, and MSB LSB orders will be handled under the hood of that particular CPU's microcode.
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