• 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("
    ");        
    43         printf("%d, ", (unsigned char)gDotNum[i]);
    44 
    45     }
    46     
    47     return 0;
    48 }
  • 相关阅读:
    分析函数
    HIBERNATE锁机制
    面试小计
    java Base64算法的使用
    Mac & XCode 使用技巧总结
    设计模式-15 模板模式
    Struts学习总结-02 上传文件
    java学习总结
    Java中 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念
    设计模式-14 MVC模式
  • 原文地址:https://www.cnblogs.com/utank/p/5570738.html
Copyright © 2020-2023  润新知