- 论坛徽章:
- 0
|
最近在看位序,即bit order。(当然我的问题可能与之无关,也可能有关,我也不知道)- #include <stdio.h>
- //#define BYTE unsigned char
- #define BYTE char
- typedef struct
- {
- BYTE a:1;
- BYTE b:1;
- BYTE c:1;
- BYTE d:1;
- BYTE e:1;
- BYTE f:1;
- BYTE g:1;
- BYTE h:1;
- }TestBit;
- int main(int argc, char* argv[])
- {
- char c = 0x96; /* 10010110 */
- TestBit *q = NULL;
-
- q = (TestBit *)&c;
- printf("q->a = %d\n", q->a);
- printf("q->b = %d\n", q->b);
- printf("q->c = %d\n", q->c);
- printf("q->d = %d\n", q->d);
- printf("q->e = %d\n", q->e);
- printf("q->f = %d\n", q->f);
- printf("q->g = %d\n", q->g);
- printf("q->h = %d\n", q->h);
- return 0;
- }
复制代码 我的问题是在这两个define这里。
当用#define BYTE unsigned char时,输出是:
[pwp@localhost bit_order]$ ./bit_order
q->a = 0
q->b = 1
q->c = 1
q->d = 0
q->e = 1
q->f = 0
q->g = 0
q->h = 1
当时当用#define BYTE char时,输出是:
[pwp@localhost bit_order]$ ./bit_order
q->a = 0
q->b = -1
q->c = -1
q->d = 0
q->e = -1
q->f = 0
q->g = 0
q->h = -1
为什么会是-1呢? |
|