使用位
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)
測試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
}

2



3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

posted on 2011-01-04 14:15 呆人 閱讀(339) 評論(0) 編輯 收藏 引用 所屬分類: 數據結構