Who can I convert a word (int or 16 bits) to 2 bytes (char or 8 bits)
I tried follolowing but it didn't work:
TX_Buffer[length] = (char)(crc<<8) ;
TX_Buffer[length+1] = (char)(crc && 0x00ff);
crc is word and TX_Buffer is byte
Who can I convert a word (int or 16 bits) to 2 bytes (char or 8 bits)
I tried follolowing but it didn't work:
TX_Buffer[length] = (char)(crc<<8) ;
TX_Buffer[length+1] = (char)(crc && 0x00ff);
crc is word and TX_Buffer is byte
Don't you mean crc>>8? crc<<8 will move everything left (more significant) 8 bits, and thus take it out of the char range.
Also, you mean &, not &&. & is a bitwise and, && is a logical and.
Last edited by cwr; 09-30-2005 at 03:53 AM. Reason: typo
Yes of course, my fault, just a beginner in C, thank you very much
after the above, the character array bytes will contain the binary representation of the integer.Code:unsigned char bytes[sizeof(int)]; int n = 123; *(int *)bytes = n;