Can you please tell me if there are any new versions of the c ++ standard or the standard library that work with bits in large data arrays.
For example, I have an array
char* buffer; in which it is necessary to determine the value of the n-th bit (for example, 12345th) or set such a bit or reset.
Now I use my functions:
uint8_t get_bit ( uint8_t* buffer const uint32_t index ) const { const uint32_t bytesIndex = index/ 8; const uint32_t bitsIndex = index % 8; const uint32_t mask = (1 << bitsIndex); const uint32_t maskValue = (buffer[bytesIndex] & mask); return ((maskValue == 0) ? (0) : (1)); } void set_bit ( uint8_t* buffer const uint32_t index, const uint8_t value ) { const uint32_t bytesIndex = buffer/ 8; const uint32_t bitsIndex = buffer % 8; const uint32_t mask = (1 << bitsIndex); buffer[bytesIndex] = (value == 1) ? (buffer[bytesIndex] | mask) : (buffer[bytesIndex] & !mask); } which still makes it somewhat difficult to read the code :)
Maybe in C ++ 11 + there were some built-in tools, more beautiful and faster than self-written?
bitsetdo not want to use? Or? at worst,vector<bool>? - Harryget_bit-set_bit- everything is clear. The only problem is that the size of the array is not transmitted anywhere and the output beyond its limits is not monitored. - VTTboolwould still allocate a byte for eachbool- Zhihar