For my LZW compression code. I chose to store the codes in 9-bit codes, dictionary size will be 512, so there will be room for only 256 new symbols. Now I feel like I didn't choose the right buffer for the job:
byte[] buffer = new byte[3];
This buffer is more suited to store for 12 bits, what is the equivalent for 9 bits and how can I store the 9 bits in the buffer correctly?
I used this to store 8 bits in buffer[0] and 4 bits in buffer[1]. What is the equivalent for 9 bits?
buffer[0] = (byte) (code & 255);
buffer[1] = (byte) ((code >> 8) << 4);