将一个十六进制拆分为2个十六进制值 [英] Spliting an hex into 2 hex values

查看:284
本文介绍了将一个十六进制拆分为2个十六进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我有一个十六进制的 0x6002 ,我必须将其拆分为 0x60 0x02
我该怎么做?

I have a problem I have an Hexadecimal like 0x6002 and I have to split it into 0x60 and 0x02. how do I do that?

我在cpp中编程,必须与网络端口进行通信。为此,我有一个地址必须在中间分开,我的问题是我将十六进制存储在 Uint8 中,将数字转换为小数。我该如何解决我的问题?

I progam in cpp and have to communicate with a network port. For that I have an address which I have to split in the middle my issue is that I store the hex in a Uint8 wich converts the number to a decimal. how can i solve my problem?

推荐答案

uint16_t port = 0x6002;
uint8_t high = (port >> 8) & 0xFF;
uint8_t low = port & 0xFF;

这篇关于将一个十六进制拆分为2个十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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