位运算,今天写的一个玩具程序

#include <stdio.h> void printBits(char *p, int num) {     void printByte(char *);     int i = num-1;     for(; i>=0; i--)         printByte(p+i);     printf("\n"); } void printByte(char *p) {     int i = 0;     for(; i<8; i++)     {         if (128>>i & *p)            printf("1");         else            printf("0");         if(i==3)            printf(" ");     }     printf(" . "); } int main() {     int i = -1;     char * p = (char *) & i;     printBits(p, sizeof(int));     return 0; } ////////////////////////////////////// ///输出 1111 1111 . 1111 1111 . 1111 1111 . 1111 1111 . ////////
相关文章
相关标签/搜索