Tomás wrote:
Jhon posted:
Hi every one,
I got very basic question, here i go:
Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.
Please note that left hand side just accept a single bit for every
operation.
how to do this , thanks.
I'll give a hand, rather than do the work for you.
unsigned long ManCode(unsigned long const x)
{
unsigned long result
for(unsigned i {
if ( ! GetBit(x,i) ) ++result;
}
return result;
}
The above routine returns the zero bit population count of its input. I
believe the original poster wants to encode a bit stream, replacing
each set bit with a set/unset bit pair and each unset bit with an
unset/set bit pair. So the bit sequence:
001100101
would be encoded as:
010110100101100110
A possible implementation (assuming stdint.h is available) would be to
encode the stream 16 bits at a time:
#include <stdint.h>
uint32_t ManCode( uint16_t x)
{
uint32_t result = 0;
for (int i = 0; i < 16; i++)
{
if (x & 0x8000)
result |= 0x02;
else
result |= 0x01;
x <<= 1;
result <<= 2;
}
return result;
}
Greg