I have this code for compressing data. First, I collect the last 3 on bits of a byte. Then I record the rest. Using a simple algorithm, I strip the differences of their lengths. This is seen in the code just below.

```
int cx_lo_bits = (j > -1) ? j : -1;
int cx_mid_bits = (i > -1) ? (i - cx_lo_bits) : -1;
{
int tf_i = ((cx_mid_bits)%2 == 1) ? 1 : 0;
(tf_i == 1) ? cx_mid_bits-- : 0;
cx_mid_bits /= 2;
alpha <<= (cx_mid_bits) - 1;
alpha <<= 1;
alpha = alpha.to_ullong() + tf_i;
alpha <<= 1;
alpha = alpha.to_ullong() + 1;
}
```

After this, I use the below code to fashion it back out. If I am doing it right, I should get somewhere between 0-7 for this value that comes out of cx_mid_bits. Because I have cx_hi_bits covering 0-8, and when it finds one it deletes this 1 bit on the end and uses the rest to find cx_mid_bits. So, I am trying to put up a good bid at compression in my ends. I would like to know what I’m doing wrong though, herein. Because the cx_mid_bits (not cx_lo or cx_hi) is over 20 sometimes. I’m not sure how it’s possible. I’d like to know though and wonder if anyone here can spot the issue.

```
binary_str >>= 1;
p = binary_str[0];
buffer_size = binary_str.to_string().find_first_of('1');
cout << buffer_size << "*" << flush;
uint8_t cx_mid_bits = abs(buffer_size * 2) + 1;
(p) ? cx_mid_bits++ : 0;
binary_str >>= 1;
binary_str >>= buffer_size;
cout << cx_mid_bits + 1 << " " << flush;
alpha = alpha.to_ullong() + pow(2, cx_lo_bits + cx_mid_bits - 1);
```

Source: Windows Questions C++