Rod Pemberton said:
Jhon said:
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[sic,insert] one and if it is one
then i would be adding[sic,inserting] zero. Folks say it manchester coding.
Please note that left hand side just accept a single bit for every
operation.
If you have binary 11001 11010, you want it converted to binary 1010010110
1010011001. It that correct?
If you can separate your data into nybbles (4-bits), the routine below
converts to Manchester. It's not fast or efficient or easy to use with
5-bits or 10-bits. If your wanting to use Manchester for something serious,
you'll need a better algorithm or a lookup table. Basically, Manchester
data is an interleave of the bits of a value with the inverted bits of that
value:
data 11001 11010
inverted 00110 00101
interleaved 1010010110 1010011001
#include <stdio.h>
#include <stdlib.h>
unsigned short man_nyb(unsigned short value)
{
unsigned short v1,v2;
char i;
v1=value&0x0F;
v2=v1^0x0F;
value=0;
for(i=3;i>=0;i--)
{
value|=((v1&(1<<i))<<(i+1));
value|=((v2&(1<<i))<<i);
}
return(value);
}
/* 11001 11010 */
/* 11 0011 1010 */
/* 0x03 0x0A */
/* 1010010110 1010011001 */
/* 1010 0101 1010 1001 1001 */
/* 0x0A 0x05 0x0A 0x09 0x09 */
int main(void)
{
unsigned short start=0;
start=0x03;
printf("0x03:%02x 0x5A:%04x\n",start,man_nyb(start));
start=0x0A;
printf("0x0A:%02x 0x99:%04x\n",start,man_nyb(start));
return(0);
}
Rod Pemberton