News for hackers. Stuff that matters.
Re:Low Level Bit Hacks You Absolutely Must Know by antipax on Tuesday June 30, 2009 @04:15PM (#681494)
I guess I should be the one to provide the usual warning that C and C++ make no guarantees about the in-memory representation of the built-in types, and that this type of code can be very dangerous.

It is, however, very cool when it works.

Re:Low Level Bit Hacks You Absolutely Must Know by jules on Tuesday June 30, 2009 @04:27PM (#681517)
No. They might not guarantee the representation, but they do guarantee that the operations (e.g. >> & |) work.
Re:Low Level Bit Hacks You Absolutely Must Know by scott_s on Tuesday June 30, 2009 @05:24PM (#681612)
There actually are guarantees, they're just a guarantee of ranges. (When bit-twiddling, you always want to use the unsigned version.)

char is guaranteed to be at least 8 bits.

short is guaranteed to be at least 16 bits.

int is guaranteed to be at least 16 bits.

long is guaranteed to be at least 32 bits.

long long is guaranteed to be at least 64 bits.

unsigned long is guaranteed to be the same size as a pointer.

Re:Low Level Bit Hacks You Absolutely Must Know by Locke1689 on Wednesday July 01, 2009 @12:13AM (#682083)
Look up C99 and stdint.h. You will be pleasantly surprised.
Re:Low Level Bit Hacks You Absolutely Must Know by antipax on Wednesday July 01, 2009 @09:55AM (#682628)
Consider me educated.
Re:Low Level Bit Hacks You Absolutely Must Know by mahmud on Tuesday June 30, 2009 @08:19PM (#681879)
you want to use "unsigned" and "register".
Re:Low Level Bit Hacks You Absolutely Must Know by mahmud on Tuesday June 30, 2009 @08:19PM (#681878)
you want to use "unsigned" and "register".