#include
#include
using namespace std;
void main()
{
struct test
{
//在这里测试就可以发现其规律,有无unsigned、a:1 a:2 a:4 a:8 a:16 a:32 以及用char的各值来试验就可发现位域的规律
unsigned int a:8;
};
test t1;
t1.a = 0;
cout<<"十进制 -> 0: "<
cout<<"十六进制-> 0: "<
cout<
t1.a = 1;
cout<<"十进制 -> 1: "<
cout<<"十六进制-> 1: "<
cout<
t1.a = 2;
cout<<"十进制 -> 2: "<
cout<<"十六进制-> 2: "<
cout<
t1.a = 3;
cout<<"十进制 -> 3: "<
cout<<"十六进制-> 3: "<
cout<
t1.a = 126;
cout<<"十进制 -> 126: "<
cout<<"十六进制-> 126: "<
cout<
t1.a = 127;
cout<<"十进制 -> 127: "<
cout<<"十六进制-> 127: "<
cout<
t1.a = 128;
cout<<"十进制 -> 128: "<
cout<<"十六进制-> 128: "<
cout<
t1.a = 129;
cout<<"十进制 -> 129: "<
cout<<"十六进制-> 129: "<
cout<
t1.a = 253;
cout<<"十进制 -> 253: "<
cout<<"十六进制-> 253: "<
cout<
t1.a = 254;
cout<<"十进制 -> 254: "<
cout<<"十六进制-> 254: "<
cout<
t1.a = 255;
cout<<"十进制 -> 255: "<
cout<<"十六进制-> 255: "<
cout<
t1.a = 256;
cout<<"十进制 -> 256: "<
cout<<"十六进制-> 256: "<
cout<
t1.a = 257;
cout<<"十进制 -> 257: "<
cout<<"十六进制-> 257: "<
cout<
t1.a = 258;
cout<<"十进制 -> 258: "<
cout<<"十六进制-> 258: "<
cout<
t1.a = 259;
cout<<"十进制 -> 259: "<
cout<<"十六进制-> 259: "<
cout<
t1.a = 260;
cout<<"十进制 -> 260: "<
cout<<"十六进制-> 260: "<
cout<
t1.a = 261;
cout<<"十进制 -> 261: "<
cout<<"十六进制-> 261: "<
cout<
t1.a = 262;
cout<<"十进制 -> 262: "<
cout<<"十六进制-> 262: "<
cout<
t1.a = 263;
cout<<"十进制 -> 263: "<
cout<<"十六进制-> 263: "<
cout<
t1.a = 264;
cout<<"十进制 -> 264: "<
cout<<"十六进制-> 264: "<
cout<
t1.a = 65533;
cout<<"十进制 -> 65533: "<
cout<<"十六进制-> 65533: "<
cout<
t1.a = 65534;
cout<<"十进制 -> 65534: "<
cout<<"十六进制-> 65534: "<
cout<
t1.a = 65535;
cout<<"十进制 -> 65535: "<
cout<<"十六进制-> 65535: "<
cout<
t1.a = 65536;
cout<<"十进制 -> 65536: "<
cout<<"十六进制-> 65536: "<
cout<
t1.a = 65537;
cout<<"十进制 -> 65537: "<
cout<<"十六进制-> 65537: "<
cout<
}
2017年计算机等级考试二级C++辅导:位域具体存放数值测试.doc