Search code examples
javaendiannessmaskingbitmask

Bitmask in big endian


This isn't a question as much as it's a sanity check!

If you needed to read 4 bytes into Java as a bitmask in Big endian and those bytes were:

0x00, 0x01, 0xB6, 0x02.

Making that into an int would be: 112130

The binary would be: 00000000000000011010011000000010

The endian of a series of bytes wouldn't affect the bit position, would it?

Thanks

Tony


Solution

  • Endian-ness reflects the ordering of bytes, but not the ordering of the bits within those bytes.

    Let's say I want to represent the (two-byte) word 0x9001. If I just type this out in binary, that would be 1001000000000001.

    If I dump the bytes (from lower address to higher) on a big-endian machine, I would see 10010000 00000001.

    If I dump the bytes (from lower address to higher) on a little-endian machine, I would see 00000001 10010000.