Masking a bit in C returning unexpected result
Posted
by
Eamorr
on Stack Overflow
See other posts from Stack Overflow
or by Eamorr
Published on 2011-01-14T19:43:03Z
Indexed on
2011/01/14
19:53 UTC
Read the original article
Hit count: 208
0x7F000000
is 0111 1111 0000 0000 0000 0000 0000 0000
in 32 bit binary.
0x01000058
is 0000 0001 0000 0000 0000 0000 0101 1000
.
When I AND the two numbers together I expect 0000 0001 0000 0000 0000 0000 0000 0000
, but for some reason I get 0.
Here is my code:
#define MASK_binop 0x80000000
#define MASK_operation 0x7F000000
int instruction=atoi(line);
if((MASK_binop & instruction)>0)
printf("binop\n");
else if((MASK_operation & instruction)>0)
printf("operation\n");
Each of the above comparisons keeps returning zero. Is it something to do with 32/64 bits? I'm using 64-bit compiler.
© Stack Overflow or respective owner