Search code examples
c++uint8t

Map 10Bit buffer to 8Bit


I have a 10 bit SDI stream, when I receive it, it will be stored into uint8_t *buffer and off course when I read it I get completely different value from what expected, except for the first:

10Bit -> 00 0000 0001 | 00 0101 1010 → Hex: A5 10

8 Bit -> 0000 | 0000 0100 | 0101 1010 → Hex: A5 40

is there a function I can use to map it correctly? (C++ style)

If it does not exist, how do I implement it?


Solution

  • Basically you need to use fread() with the correct parameters to read exactly 5 bytes, i.e. 40 bits, into a temporary buffer. You use that amount because it corresponds to a whole number of bytes on the input stream and also a whole number of output bytes on the output stream.

    You then use left and right SHIFTs (<< and >>) and bitwise masks (&) to extract the 5 output bytes and put them in your uint8_t buffer.