fly swatter fly swatter - 1 year ago 85
C Question

bitwise anding unsigned long with 0xffffffff

Below is some code from switch statement.

returns an
unsigend long
Could somebody explain why
is bitwise anded with
The mcu is 32 bit.

#define WriteMemory(A,V) *(volatile unsigned long*)(A)=(V)

case 'b':
value = getvalue();
value &= 0xffffffff;
WriteMemory(2147455555, value);

Answer Source

unsigned long isn't guaranteed to be 32 bit by the C standard. It is only guaranteed to be able to hold 32 bit values.

and-ing it with 0xffffffff makes sure any bits over the 32 are zeroed out.