Created
September 20, 2010 22:02
-
-
Save mikeash/588731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BIT_SET(array, bit) (array[bit / 8] |= (1 << (bit % 8))) | |
#define BIT_CLEAR(array, bit) (array[bit / 8] &= ~(1 << (bit % 8))) | |
#define BIT_GET(array, bit) ((array[bit / 8] | (1 << (bit % 8))) != 0) | |
uint8_t array[5]; | |
bzero(array, sizeof(array); | |
BIT_SET(array, 18); | |
BIT_GET(array, 18); |
- I don't like C++.
- More important: this was a quickie example of how zero-based array indexing can be easier to work with.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why don't just use std::bitset? :)