Skip to content

Instantly share code, notes, and snippets.

@cloderic
Created September 22, 2011 09:30
Show Gist options
  • Save cloderic/1234411 to your computer and use it in GitHub Desktop.
Save cloderic/1234411 to your computer and use it in GitHub Desktop.
C/C++ bitsets
class Car
{
public:
Car()
:_status(0x00)
{
}
void setLocked()
{
_status |= statusLocked;
}
void setParked()
{
_status |= statusParked;
}
void unsetLocked()
{
_status &= (~statusLocked);
}
void unsetParked()
{
_status &= (~statusParked);
}
void toggleLocked()
{
_status ^= statusLocked;
}
void toggleParked()
{
car ^= statusParked;
}
bool isLocked() const
{
return car & statusLocked;
}
bool isParked() const
{
return car & statusParked;
}
private:
static const char statusLocked = 0x01; // 0000 0001
static const char statusParked = 0x02; // 0000 0010
char _status;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment