加入十六进制值来创建一个16位值 [英] Joining hex values to create a 16bit value

查看:181
本文介绍了加入十六进制值来创建一个16位值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林收到这是最,中东和三个UINT8值至少地块价值的有效位数:

Im receiving three uint8 values which are the Most, Middle and Least Significant Digits of a plot value:

EG:在控制台打印(%C):

EG: Printed in console (%c):

   1 A 4

我需要将它们传递到它接受uint16_t的信号视图界面图示。到目前为止,即时通讯做的方式工作不正常。

I need to pass them into a signal view UI grapher which accepts a uint16_t. So far the way im doing it is not working correctly.

 uint16_t iChanI = (bgp->iChanIH << 8) + (bgp->iChanIM <<4 ) + bgp->iChanIL;
 uint16_t iChanQ = (bgp->iChanQH << 8) + (bgp->iChanQM <<4) + bgp->iChanQL;

[self updateSView:iChanI ichanQ:iChanQ];

难道我正确地将它们合并,或只是增加值?

Am i merging them correctly, or just adding the values?

任何帮助很多AP preciated,

Any help is much appreciated,

谢谢,

推荐答案

您首先需要每一个十六进制字符转换为其对应的4位(半字节)再presentation,然后将它们合并成一个 int16_t ,例如:

You first need to convert each hex character to its equivalent 4 bit (nybble) representation, and then merge them into an int16_t, e.g.

uint8_t to_nybble(char c)
{
    return 'c' >= '0' && c <= '9' ? c - '0' : c - 'A' + 10;
}

uint16_t iChanI = (to_nybble(bgp->iChanIH) << 8) |
                  (to_nybble(bgp->iChanIM) << 4) |
                   to_nybble(bgp->iChanIL);

这篇关于加入十六进制值来创建一个16位值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆