Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bitset>
- #include <iostream>
- #include <array>
- using u32 = unsigned int;
- std::array<u32, 1024> data{};
- u32 bit_buf = 0;
- u32 bit_pos = 0;
- u32 write_ptr = 0;
- void put_bit(u32 bit) {
- if (bit_pos > 32) {
- data[write_ptr++] = bit_buf;
- bit_buf = 0;
- }
- bit_buf |= (bit << bit_pos);
- bit_pos++;
- }
- void put_byte(int byte) {
- if (bit_pos > 24) {
- const u32 num_bits = 32 - bit_pos;
- const u32 mask = (1 << num_bits) - 1;
- bit_buf |= ((byte & mask) << bit_pos);
- data[write_ptr++] = bit_buf;
- byte >>= num_bits;
- bit_buf = 0;
- }
- bit_buf |= (byte << bit_pos);
- bit_pos++;
- }
- void put_dword(u32 dword) {
- if (bit_pos > 0) {
- const u32 num_bits = 32 - bit_pos;
- const u32 mask = (1 << num_bits) - 1;
- bit_buf |= ((dword & mask) << bit_pos);
- data[write_ptr++] = bit_buf;
- dword >>= num_bits;
- bit_buf = 0;
- }
- bit_buf |= (dword << bit_pos);
- bit_pos++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement