Jump to content

  • Log In with Google      Sign In   
  • Create Account

Dan Berliner

Member Since 06 Apr 2011
Offline Last Active Feb 04 2013 10:06 AM

#4795189 Working with a C++ data type on a bit by bit level

Posted by on 06 April 2011 - 02:12 PM

int is 32 bits.
char is 8 bits.
short is 16.

My mistake there

See std::vector<bool>.

It should be specialized to use one bit per value, while working like a regular array.

I recall reading somewhere that bool was longer than 1 bit, after googling it again I see that I was incorrect. Thanks.

For people who may come here looking for the original requested solution (perhaps for a different issue), the following function will tell you if a bit is on or off in an int data type (you can modify it to use any fundamental data type:
bool isBitOn(int place, int &subject)
	return ((subject & 1<<place)==0 ? false : true);