#include <stdio.h> #include <stdint.h> #include <stddef.h> #include <stdbool.h> #include <limits.h> uint8_t ee_fat[10] = {0,}; bool getBit (uint8_t* p, size_t index) { const size_t entrySize = sizeof(p[0]) * CHAR_BIT; return p[index / entrySize] & (1 << (index % entrySize)); } void setBit (uint8_t* p, size_t index, bool value) { const size_t entrySize = sizeof(p[0]) * CHAR_BIT; const size_t bit = index % entrySize; p[index / entrySize] = (p[index / entrySize] & ~(1 << bit)) | (value << bit); } void print (uint8_t* p, size_t length) { for (size_t i = 0; i < length; ++i) { for (size_t j = 0; j < CHAR_BIT * sizeof(p[0]); ++j) { } } } int main () { setBit (ee_fat, 7, 1); setBit (ee_fat, 42, 1); print (ee_fat, sizeof(ee_fat)/sizeof(ee_fat[0])); }
Standard input is empty
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 1