serial data decoding

E

Ed

Please help!
I have a string of data as the result of serial to parallel hardware
conversion.
I need to decode this string into correct bytes.
The start of a byte position is unknown.
In this particular case, part of my data is as follows.
Serial data string: (not rs232, straight serial data)
01001010010010010101001001001001010100100010010001001010
This was read through a shift register to get 8-bit bytes to store in memory
as:
4A 49 52 49 52 24 4A
I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?
This is not a homework assignment, it is an engineering design question.
Thanks,
Ed
 
M

mlimber

Ed said:
Please help!
I have a string of data as the result of serial to parallel hardware
conversion.
I need to decode this string into correct bytes.
The start of a byte position is unknown.
In this particular case, part of my data is as follows.
Serial data string: (not rs232, straight serial data)
01001010010010010101001001001001010100100010010001001010
This was read through a shift register to get 8-bit bytes to store in memory
as:
4A 49 52 49 52 24 4A
I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?
This is not a homework assignment, it is an engineering design question.

There's no simple, out-of-the-box way. You'll have to write an
algorithm to do it. Use the bit operators (e.g., &, |, <<, and >>) or
perhaps std::bitset.

This newsgroup is for C++ language questions, not algorithm or
application design questions
(http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9), so if
you can rephrase your question as a specific language question, we
might be able to provide more assistance.

Cheers! --M
 
D

David Harmon

On Wed, 06 Dec 2006 16:25:21 GMT in comp.lang.c++, "Ed"
I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?

Some crude first approximation of code might look like:

unsigned char *in_ptr = ?, *out_ptr = ?;
int in_bytes = 32000;
unsigned char in_mask = 0xC0, in_bits = 0x40,
out_bit = 0x80, result_byte = 0;

while (in_bytes) {
unsigned char masked_bits = in_mask & *in_ptr;
if (masked_bits == in_bits) {
result_byte |= out_bit;

} else if (masked_bits == in_mask) {
error("illegal");

} // else result is zero

in_mask >>= 2;
in_bits >>= 2;
if (in_mask == 0) {
--in_bytes;
++in_ptr;
in_mask = 0xC0;
in_bits = 0x40;
}

out_bits >>= 1;
if(out_bits == 0) {
*(out_ptr++) = result_byte;
result_byte = 0;
out_bit = 0x80;
}
}
 

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

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top