0x00到0xFF二进制数值中1的的个数
Posted uTank-木头
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了0x00到0xFF二进制数值中1的的个数相关的知识,希望对你有一定的参考价值。
似乎有点无聊耶~~~~~(>_<)~~~~
1 #include <stdio.h> 2 3 static char gCharDotTab[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; 4 static char gDotNum[256] = { 5 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 6 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 7 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 8 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 9 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 10 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 11 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 12 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 13 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 14 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 15 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 16 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 17 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 18 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 19 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 20 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, 21 }; 22 23 static void prtInitCharDots(void) 24 { 25 int i; 26 27 for(i=0; i<=0xff; i++) 28 { 29 gDotNum[i] = gCharDotTab[i&0x0f] + gCharDotTab[(i>>4)&0x0f]; 30 } 31 } 32 33 int main(void) 34 { 35 int i; 36 37 prtInitCharDots(); 38 39 for(i = 0; i < sizeof(gDotNum)/sizeof(gDotNum[0]); i++) 40 { 41 if( i % 16 == 0 ) 42 printf("\r\n"); 43 printf("%d, ", (unsigned char)gDotNum[i]); 44 45 } 46 47 return 0; 48 }
以上是关于0x00到0xFF二进制数值中1的的个数的主要内容,如果未能解决你的问题,请参考以下文章