码迷,mamicode.com
首页 > 其他好文 > 详细

0x00到0xFF二进制数值中1的的个数

时间:2016-06-08 18:52:30      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:

似乎有点无聊耶~~~~~(>_<)~~~~

 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的的个数

标签:

原文地址:http://www.cnblogs.com/utank/p/5570738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!