I wants to extract the bits from the CAN message (8 bytes).
so, how to i extract bits from 8 bytes.
I wants to extract the bits from the CAN message (8 bytes).
so, how to i extract bits from 8 bytes.
Here is a chunk of code to get the bits from one byte:
on message myMessage
{
byte bitArray[8];
int iByteToRead = 0;
f_ByteToBitArray(this.byte(iByteToRead),bitArray);
write ("f_ByteToBitArray %X :Bits %X %X %X %X %X %X %X %X", iByteToRead , bitArray[0],bitArray[1],bitArray[2],bitArray[3],bitArray[4],bitArray[5],bitArray[6],bitArray[7]);
}
void f_ByteToBitArray(byte in, byte out[])
{
// 7 6 5 4 3 2 1 0
// f_ByteToBitArray 1 :Bits 0 0 0 0 0 0 0 1
// f_ByteToBitArray 2 :Bits 0 0 0 0 0 0 1 0
byte a;
a = in;
out[0] = a & 0x01;
a = a >> 1;
out[1] = a & 0x01;
a = a >> 1;
out[2] = a & 0x01;
a = a >> 1;
out[3] = a & 0x01;
a = a >> 1;
out[4] = a & 0x01;
a = a >> 1;
out[5] = a & 0x01;
a = a >> 1;
out[6] = a & 0x01;
a = a >> 1;
out[7] = a & 0x01;
}