gpt4 book ai didi

将两个 uint8_t 组合为 uint16_t

转载 作者:太空狗 更新时间:2023-10-29 16:27:24 25 4
gpt4 key购买 nike

我有以下数据

uint8_t d1=0x01; 
uint8_t d2=0x02;

我想将它们组合为 uint16_t as

uint16_t wd = 0x0201;

我该怎么做?

最佳答案

您可以使用按位运算符:

uint16_t wd = ((uint16_t)d2 << 8) | d1;

因为:

 (0x0002 << 8) | 0x01 = 0x0200 | 0x0001 = 0x0201

关于将两个 uint8_t 组合为 uint16_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15249791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com