从键盘上读取4个字符,把它们放在一个4字节的整型变量中,把这个变量的值显示为一个16进制;分解变量的4个字节,以相反的顺序输出它们,先输出低位字节
#include <iostream>
using namespace std
;
int main()
{
cout
<< "请输入4个字符" << endl
;
char a
[4];
cin
>> a
[0] >> a
[1] >> a
[2] >> a
[3] ;
int x
;
x
= (int)a
[0]*1000+ (int)a
[1] * 100+ (int)a
[2] * 10+(int)a
[3];
cout
<< hex
<<"转成十六进制为:" <<x
<< endl
;
cout
<< a
[3]
<< a
[2]
<< a
[1]
<< a
[0]
<< endl
;
system("pause");
return 0;
}
转载自:黑凤梨の博客
转载请注明原文地址:https://blackberry.8miu.com/read-2523.html