# Thoughts about how to bit shift large amounts of data

• 07-07-2011, 10:37 PM
whytheheckme
Thoughts about how to bit shift large amounts of data
Hello!

I'm new to the forums :(party):, so go easy, eh?

I'm trying to write an application that does the following:
• Recieve UDP Packet
• Sequence with remainder of previous packet
• Find start bits, read following 100 bytes
• Reformat these bytes from 12 bits -> 16 bits
• Rebroadcast 512 byte segments

Let me explain the situation further.

Each UDP packet comes in with 512 bytes of data. Somewhere in the data are some start bits (a 24 bit word). I need to find this word, and then read the 100 bytes following this word. The data contained within these 100 bytes are in 12 bit format, so I need to recondition the data such that there are 4 leading 0s on each piece (making the values 2 bytes a piece). I then need to rebroadcast this data.

Here are some of the issues:

Data will always be split between packets; including the synch word sometimes. I need to be able to double buffer the packets, and remove data away as this happens (I'm not so worried about being able to do this part)

What I AM having trouble with, is how to handle this data in a bit-wise fashion. While the synch word DOES fit nicely into 3 bytes, it's not guaranteed that it will fall spatially into 3 bytes (e.x. if the synch word was 000000000000000000000001, the word that i'm looking for COULD be 00 00 01, or (XXX0) 00 00 0 (001X), or (XX00) 00 00 0(01XX), etc. I would think that I need to start at the beginning, bitshift all of the data and read 24 bytes until I find my synch word.

I also need some help thinking about how to recondition those 12 bit values into two bytes.

I know its a lot! Thanks for any help that anyone can give :(happy):

Jacob
• 07-07-2011, 11:06 PM
Norm
Quote:

how to recondition those 12 bit values into two bytes.
0123.4567 89AB.0123 4567.89AB => 0000.0123 4567.89AB 0000.0123 4567.89AB
Every 3 bytes go to 4 bytes

How does that fit into 100 bytes? It's not a multiple of 3?
• 07-08-2011, 12:42 AM
whytheheckme
Quote:

Originally Posted by Norm
0123.4567 89AB.0123 4567.89AB => 0000.0123 4567.89AB 0000.0123 4567.89AB
Every 3 bytes go to 4 bytes

How does that fit into 100 bytes? It's not a multiple of 3?

I'm sorry, I wasn't clear.
There will be 100 bytes worth of data in the end.. 75 bytes worth of data to start with.
• 07-08-2011, 12:48 AM
Norm
To get an algorithm, write out the input bits/bytes on one line and the output bits/bytes on a line below and map from one to the other.
Looks like a few shifts and some ANDs and ORs will be involved.
Use two arrays of bytes. Take 3 bytes from one and convert them to 4 bytes in the other.