使用位

使用位

 1  #include < windows.h >
 2  #pragma pack(push, 1 )
 3  typedef     struct     tagBite
 4  {
 5      UINT    bite3: 8 ;
 6      UINT    bite2: 8 ;
 7      UINT    bite1: 8 ;
 8      UINT    bite0: 8 ;
 9  }HBITE, * PHBITE;
10  typedef    union    tagDData
11  {
12      DWORD    dword;
13      BYTE     byte [ 4 ];
14      HBITE    bite;
15  }DDATA, * PDDATA;
16  #pragma pack(pop)
测试
 1 void  testBite()
 2 {
 3    PHBITE pHbite = new HBITE;
 4    pHbite->bite0 =0;
 5    pHbite->bite1 =0;
 6    pHbite->bite2 =1;
 7    pHbite->bite3 =1;
 8
 9    UINT *pData = (UINT*)pHbite;
10    printf("data=%d\n",*pData);
11
12    HBITE hBite;
13    UINT uData=10;
14    memcpy(&hBite,&uData,sizeof(uData));
15
16    printf("hBite.bite3=%d,hBite.bite2=%d\n",hBite.bite3,hBite.bite2);
17}

你可能感兴趣的:(使用位)