Why the and operator acts differently when used:
- with un unsigned int
-
with a byte array represiting the same value when casted to (uint*)
unsafe { fixed (byte* i = new byte[4] { 0x02, 0x03, 0x04, 0xFF }) { uint m = 0x020304FF; Console.WriteLine("{0:X}",m & 0xFF000000); Console.WriteLine("{0:X}",*(uint*)i & 0xFF000000); } }
result is
2000000
ff000000
Assuming a 32 bits little-endian system (like any Intel processor, in the vast majority of today’s computers), casting the address of the byte-array {02 03 04 FF} to the address of a 32 bit int will result in an int with the value 0xFF040302. Hence the result.
In other words, your assumption that it’s “the same value” is not correct.