由4个字符组成的十六进制数 [英] Number made of 4 chars with hex
本文介绍了由4个字符组成的十六进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IAM编程在C + +和IAM与另一个愚蠢的问题。如果我有4个字符,像这样:
Iam programming in C++ and Iam comming with another "stupid" problem. If I have 4 chars like these:
char a = 0x90
char b = 0x01
char c = 0x00
char d = 0x00
当这一切表示十六进制数0x00000190,数。
如何将这些字符转换为一个int?我知道我可以做
when that all means hexadecimal number 0x00000190 which is 400 decimal number. How do I convert these chars to one int? I know i can do
int number = a;
但这只会将一个字符转换为int。
but this will convert only one char to int. Could anybody help please?
推荐答案
您可以使用:
int number = (a & 0xFF)
| ((b & 0xFF) << 8)
| ((c & 0xFF) << 16)
| ((d & 0xFF) << 24);
使用无符号值会更简单。
It would be simpler with unsigned values.
这篇关于由4个字符组成的十六进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文