c++ 结构体位域操作 进制转换

 1 #include "iostream"
 2 using namespace std;
 3 
 4 typedef struct _AutoWithWheel
 5 {
 6     int enable:4;
 7     int Axis:4;
 8     int pulse:8;
 9     
10 }AutoWithWheel,*pAutoWithWheel;
11 void main()
12 {
13     AutoWithWheel aww={0,0,0};
14     char binaryarray[255];
15     aww.pulse=-1;
16     aww.enable=-1;
17     cout<<"size of aww: "<<sizeof(aww)<<endl;
18     cout<<aww.Axis<<endl;
19     cout<<"size of int: "<<sizeof(int)<<endl;
20     
21 int * ptestintvar=(int *)(&aww);
22     itoa(*ptestintvar,binaryarray,2);
23     
24     cout<<"force conv addr: "<<ptestintvar<<endl;
25     cout<<"force conv content: "<<binaryarray<<endl;
26     int var;
27     cout<<"test"<<endl;
28     cin>>var;
29 }
30 /*out
31 size of aww: 4
32 0
33 size of int: 4
34 force conv addr: 0018F884
35 force conv content: 1111111100001111
36 test
37 */
test code

 

posted on 2013-05-20 15:17  zhiying678  阅读(170)  评论(0编辑  收藏  举报

导航