小编how*_*ith的帖子

将 8 位数据作为 7 位数据进行访问

我有一个 100 的数组uint8_t,它被视为 800 位的流,并且一次处理 7 位。换句话说,如果 8 位数组的第一个元素成立0b11001100,第二个元素成立ob11110000,那么当我以 7 位格式读取它时,7 位数组的第一个元素将是0b1100110,第二个元素将0b0111100是其余 2 位保存在第 3 位中。我尝试的第一件事是工会...

struct uint7_t {
    uint8_t i1:7;
};

union uint7_8_t {
    uint8_t u8[100];
    uint7_t u7[115];
};
Run Code Online (Sandbox Code Playgroud)

但当然,所有内容都是字节对齐的,我本质上最终只是丢失了每个元素的第 8 位。

有谁知道我该怎么做?

需要明确的是,这是联合结果的视觉表示:

xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx8 位数据的 32 位
0xxxxxxx 0xxxxxxx 0xxxxxxx 0xxxxxxx7 位数据的 32 位。

这代表了我想做的事情:

xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx8 位数据的 32 位
xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxx7 位数据的 32 位。

我知道最后的位可能会被填充,但这没关系,我只是想以某种方式一次访问每个字节 …

c++ arrays 7-bit unions 8-bit

5
推荐指数
1
解决办法
3761
查看次数

How to use SerialPort class more reliably

I've been using the SerialPort class for a little while in an application that communicates with some external hardware that I've designed. During the debugging process of said hardware, I found a few things to be unreliable, and I recently stumbled across this which seems to be onto something.

I'm trying to implement this into my application, however I have two questions about receiving data...

So, in the article I linked, the author mentions that the DataReceived event is problematic, …

c# serial-port

4
推荐指数
1
解决办法
1946
查看次数

标签 统计

7-bit ×1

8-bit ×1

arrays ×1

c# ×1

c++ ×1

serial-port ×1

unions ×1