#include <stdio.h>
#include <assert.h>
typedef struct Hello{
unsigned h: 3,
m: 1,
l: 12;
} Hello;
int main(){
int h;
for (h=0; h < 10000; h++){
Hello *hello = (Hello*)(&h);
//printf("low:%d\nhigh:%d\n", hello->l, hello->h);
//printf("low:%d\nhigh:%d\n", h>>3, h>>13<<3);
printf("h = 0x%x, Hello={l=%x, m=%x,h=%x}\n",h ,hello->l,hello->m, hello->h);
printf("high:hello.h= h%8 = %x and hello.h=%x\n",h%8 , hello->h);
printf("last: h>>12 = %x \n",h>> 4);
assert(hello->l == h >> 4 );
assert(hello->m == (h & 15) >> 3);
assert(hello->m == h % 16 /8);
assert(hello->h == h % 8 );
}
}
转载于:https://my.oschina.net/innovation/blog/1492630