Question: Bitwise compression Write a compression function that reads in an array of numbers a where each number is from 0 to 3 (2 bits). Compress
Bitwise compression
Write a compression function that reads in an array of numbers a where each number is from 0 to 3 (2 bits). Compress into a single 64-bit word (you can fit 32 numbers in one word), then write out to output. For example, if you have 65 numbers in a, then you should write out 3 numbers into output, the first two are full, and the last one has only a single value.
uint64_t compress(uint32_t a[], uint32_t len, uint64_t output[]);
c++ file:
#include
uint64_t compress(const uint32_t in[], uint32_t len, uint64_t out[]);
int main(){ uint32_t a[65]; uint64_t out[3] = {0,0,0}; for (int i = 0; i < 65; i++) { a[i] = i % 4; } uint64_t out_len = compress(a, 65, out); for (uint32_t i = 0; i < out_len; i++) { cout << bitset<64>(out[i]) << '\t'; cout << ' '; }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
