- 论坛徽章:
- 0
|
回复 #5 ljmmail 的帖子
<code>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int ac, char *av[])
{
struct {
unsigned int a1:1 ;
unsigned int a2:1 ;
unsigned int a3:1 ;
unsigned int a4:1 ;
unsigned int a5:1 ;
unsigned int a6:1 ;
unsigned int a7:1 ;
unsigned int a8:1 ;
unsigned int a11:1 ;
unsigned int a12:1 ;
unsigned int a13:1 ;
unsigned int a14:1 ;
unsigned int a15:1 ;
unsigned int a16:1 ;
unsigned int a17:1 ;
unsigned int a18:1 ;
unsigned int a21:1 ;
unsigned int a22:1 ;
unsigned int a23:1 ;
unsigned int a24:1 ;
unsigned int a25:1 ;
unsigned int a26:1 ;
unsigned int a27:1 ;
unsigned int a28:1 ;
unsigned int a31:1 ;
unsigned int a32:1 ;
unsigned int a33:1 ;
unsigned int a34:1 ;
unsigned int a35:1 ;
unsigned int a36:1 ;
unsigned int a37:1 ;
unsigned int a38:1 ;
} bb;
int c = 0x132f;
memcpy(&bb, &c, sizeof(int));
printf("0x%x ", c );
printf("%d%d%d%d %d%d%d%d ", bb.a1, bb.a2, bb.a3, bb.a4, bb.a5, bb.a6, bb.a7, bb.a ;
printf("%d%d%d%d %d%d%d%d ", bb.a11, bb.a12, bb.a13, bb.a14, bb.a15, bb.a16, bb.a17, bb.a1 ;
printf("%d%d%d%d %d%d%d%d ", bb.a21, bb.a22, bb.a23, bb.a24, bb.a25, bb.a26, bb.a27, bb.a2 ;
printf("%d%d%d%d %d%d%d%d \n", bb.a31, bb.a32, bb.a33, bb.a34, bb.a35, bb.a36, bb.a37, bb.a3 ;
return 0;
}
</code>
使用上面的代码进行测试,得到结果为:
0x132f 1111 0100 1100 1000 0000 0000 0000 0000
测试环境为 MagicLinux 2.5 |
|