转换一个UINT32值转换成数组UINT8 [4] [英] Converting a UINT32 value into a UINT8 array[4]

查看:2492
本文介绍了转换一个UINT32值转换成数组UINT8 [4]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是你如何pferably独立字节序的方式UINT32值转换为UINT8数组[4](C / C ++)$ P $?此外,你将如何从UINT8阵列重建UINT32值[4],要回你开始的地方?

My question is how do you convert a UINT32 value to a UINT8 array[4] (C/C++) preferably in a manner independent of endianness? Additionally, how would you reconstruct the UINT32 value from the UINT8 array[4], to get back to where you started?

推荐答案

例如。像这样的:

UINT32 value;
UINT8 result[4];

result[0] = (value & 0x000000ff);
result[1] = (value & 0x0000ff00) >> 8;
result[2] = (value & 0x00ff0000) >> 16;
result[3] = (value & 0xff000000) >> 24;

编辑:加括号(>>似乎有更高的precedence比&安培;)

added parenthesis (>> seems to have higher precedence than &)

这篇关于转换一个UINT32值转换成数组UINT8 [4]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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