大佬教程收集整理的这篇文章主要介绍了将位域转换为int,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
typedef struct morder { unsigned int targetRegister : 3; unsigned int targetmethodOfAddressing : 3; unsigned int originRegister : 3; unsigned int originMethodOfAddressing : 3; unsigned int oCode : 4; } bitset;
我也有int数组,我想从这个数组中获取int值,表示这个位字段的实际值(这实际上是我拥有它的一部分的一些机器字,我想要int的表示形式整个字).
非常感谢.
typedef union bitsetConvertor { bitset bs; uint16_t i; } bitsetConvertor; bitsetConvertor convertor; convertor.i = myInt; bitset bs = convertor.bs;
或者你可以使用一个演员:
bitset bs = *(bitset *)&myInt;
或者你可以使用联合中的匿名结构:
typedef union morder { struct { unsigned int targetRegister : 3; unsigned int targetmethodOfAddressing : 3; unsigned int originRegister : 3; unsigned int originMethodOfAddressing : 3; unsigned int oCode : 4; }; uint16_t intRepresentation; } bitset; bitset bs; bs.intRepresentation = myInt;
以上是大佬教程为你收集整理的将位域转换为int全部内容,希望文章能够帮你解决将位域转换为int所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。