How to optimize?

F

filia&sofia

Hello, I am using bitwise operations in my data compression algorithm.
Basically, I have a buffer of n bytes from which the algorithm reads m
bits (m<=n). If m doesn't divide n, there will be some bits that need
to be transferred from end to start, because all bits must be used.
Now, the problem is that my algorithm uses many bit operations to do
this. I wish to do this as fast as possible.

Example.
n=2, m=3 and the data to the buffer from a file:

01001101 00101001 01111011 01110010 01110010

1. Fill the buffer B. B={01001101 00101001}
2. Read m bits for x times. After x=5, buffer will contain B={1} (of
course, the length of the buffer is still two bytes).
3. Now, we have to fill the buffer again. The actual problem arises
when the last bit needs to be moved to the start. If the buffer is
large, the algorithm will sequentially put one bit into a new byte
from previous byte and seven bits from the next byte. That is, B={1
0111101} and again one bit has to be moved to the next byte...

I would like to avoid this. Any suggestions? Design patterns?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top