I have 8 bit samples with random values (called headers) and I have commands with hexadecimal values, see bellow:
[8 bit][command]
\ |
\ \------------------ [01 30 00 00 = hex start the machine]
\
+-------------------+
| 00001111 = hi |
| 00000000 = hello |
| 00000101 = wassup |
+-------------------+
How do you translate the 8 bit samples to 1 byte and join it with the above hex value ?
In both languages, you can use bitwise operations.
So in C, if you have:
You can concatenate these into e.g. a 64-bit data type as follows:
If you instead want an array of output bytes (for serializing over RS-232 or whatever), then you can do something like: