Originally Posted by
cyberfish
It will work. Nothing will be interpreted in hex. Like you said, a number is just a number.
1 << 10
will shift left by 10 (decimal) bits.
I thought so, too, but...well, perhaps I have a different problem. I am writing code on 32-bit linux. According to all docs I can find, unsigned long long ints are guaranteed to be 64 bits.
Code:
$ cat example.c
#include <stdio.h>
int main (void) {
unsigned long long int flags;
int i;
flags = 0;
flags |= (1 << 2);
flags |= (1 << 21);
flags |= (1 << 49);
flags |= (1 << 63);
for (i =0; i<=63; i++) {
if ( ( flags & (1 << i ) ) != 0 )
printf ("bit %i is set\n",i);
}
}
Code:
$ gcc -o example example.c
example.c: In function ‘main’:
example.c:11: warning: left shift count >= width of type
example.c:12: warning: left shift count >= width of type
Code:
$ ./example
bit 2 is set
bit 21 is set
bit 34 is set <- incorrect
bit 53 is set <- incorrect
I'd assumed it was a hex notation problem...perhaps it's something else?