用C串连十六进制数 [英] Concatenate hex numbers in C
本文介绍了用C串连十六进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图串连4十六进制数似乎并不能做到这一点。
I've been trying to concatenate 4 hex numbers and can't seem to do it.
例如:
int a = 0x01;
int b = 0x00;
int c = 0x20;
int d = 0xF1;
//Result should be 0x010020F1
这是我使用sprintf和位运算总是切断零获取结果,让我回答像1020F1,这比我想要什么太大的不同。任何人有更好的方法?
The results that I am getting using sprintf and bitwise operations always cut off zeros, giving me answers like 1020F1, which is much different than what I want. Anybody have a better method?
推荐答案
假设 unsigned int类型A,B,C,D;
unsigned int result = (a<<24) | (b<<16)| (c<<8) | d;
这篇关于用C串连十六进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文