bit-operations

c - difficulties with bit operations

I'm debugging a program with GDB. unsigned int example = ~0; gives me: (gdb) x/4bt example 0xffd99788: 10101000 10010111 11011001 11111111 why is this not all 1's? i defined it as ~0... then the next line of code is: example>>=(31); and GDB gives me this when I try to examine the memory at bits: (gdb) x...

Understanding the bitwise AND Operator

Hello, I have been reading about bit operators in Objective-C in Kochan's book, "Programming in Objective-C". I am VERY confused about this part, although I have really understood most everything else presented to me thus far. Here is a quote from the book: The Bitwise AND Operator Bitwise ANDing is frequently used for masking operat...

Is there a more efficient way to get the length of a 32bit integer in bytes?

I'd like a shortcut for the following little function, where performance is very important (the function is called more than 10.000.000 times): inline int len(uint32 val) { if(val <= 0x000000ff) return 1; if(val <= 0x0000ffff) return 2; if(val <= 0x00ffffff) return 3; return 4; } Does anyone have any idea... a cool bi...