Chapter 27. Data Formats and Efficiency, Part 2: (Even Less) Bit-Twiddling
Difficulty: 8
Time to consider even more highly compact and memory-efficient data formats and get down to writing some bit-twiddling code.
Guru Question
To implement solution Item 26-2(e), you decide to create the following class that manages a buffer of bits. Implement it portably so that it will work correctly on all conforming C++ compilers regardless of platform.
class BitBuffer {
public:
// … add other functions as needed …// Append num bits starting with the first bit of p.//void Append(unsigned char* p, size_t num);// Query #bits in use (initially zero).//size_t Size() const;// Get num bits starting with the start-th bit,// and store the result starting with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.