I am trying to perform an exercise in C language whose scope is to encode a message in a 2Q QR-Code via Byte method. This means that a given string should be encoded in a message with:
- 4 bits for the Mode Indicator (0100 in my case);
- 8 bits for the length of the message;
- the message itself (20 characters);
- 4 null bits as End Of Message signal;
- 16 bits for
0xEC11
Padding.
I tried using a struct with bit fields like in the folloowing code, but it didn't work out, because the bit order can't be forced.
typedef struct
{
unsigned char mode : 4;
unsigned int length : 8;
unsigned char *message;
unsigned char eof : 4;
unsigned int padding : 16;
} code;
I also tried to left shift the bits of the coded message, but once again I received an error message "int value expected", which means (if I understood correctly) I can't shift a struct.
Could anybody suggest an elegant way of performing this task?