Efficient way to create / decompress large bit fields in C?

I have one microcontroller sample from a large number of ADCs and send measurements on the radio with a very low bitrate, and bandwidth becomes a problem.

Currently, each ADC only gives us 10 bits of data and is stored in a 16-bit integer. Is there an easy way to pack them in a deterministic way, so that the first dimension is at bit 0, the second at bit 10, the third at bit 20, etc.?

To make matters worse, the microcontroller is a little essential, and I do not control the accuracy of the computer on the other side.

EDIT: For now, I like @MSN to respond best, but I will respond to comments

@EvilTeach: I'm not sure if the exact bit pattern will be useful, or how best to format it with just text, but I'll think about it.

@ Jonathan Leffler: Ideally, I would pack 8 10-bit values ​​into 10 8-bit bytes. If this simplifies processing, I would calculate 3 values ​​of 4 bytes or 6 values ​​of 8 bytes (although 2 is equivalent to me, the same amount of wasted bits)

+3
source share
3 answers

0 31 10- . - 0 - 0 31 - 1. , 0 1, , 31 0 . , 0 0, , 31 1 3 .

+4

, :

:

struct adc_data { 
unsigned first :10;
unsigned second :10; 
unsigned third :10; 
};

EDIT: , .

+3

, , - . , ( 17 ), 10 , . , , 8 8. "" , , .

, , 10 acccumator ( MS) . : a b:

Accumulator     Count
(MS to LS bit)   
aaaaaaaaaa      10      After storing a
aa              2       After sending first byte
bbbbbbbbbbaa    12      After storing b
bbbb            4       After sending second byte

- .

0

Source: https://habr.com/ru/post/1739801/


All Articles