2011年4月16日

用位数组计算整数中1的个数

摘要: //// main.c// bitcounts//// Created by Cheney Shen on 11-4-16.// Copyright 2011年 __MyCompanyName__. All rights reserved.//#include <stdio.h>static int bitcounts[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};int bitcount(unsigned int u) { int n = 0; for(; u != 0; u >>= 4) n += bitc 阅读全文

posted @ 2011-04-16 03:25 Cheney Shen 阅读(326) 评论(0) 推荐(0) 编辑

任意进制的转换函数

摘要: //// main.c// baseconv//// Created by Cheney Shen on 11-4-16.// Copyright 2011年 __MyCompanyName__. All rights reserved.//#include <stdio.h>#include <limits.h>#include <string.h>char* baseconv(unsigned long long, int);int main (int argc, const char * argv[]){ printf("the result 阅读全文

posted @ 2011-04-16 02:56 Cheney Shen 阅读(284) 评论(0) 推荐(0) 编辑

位数组实现用筛法(Sieve of Eratosthnes)计算素数

摘要: //// main.c// bitarray//// Created by Cheney Shen on 11-4-16.// Copyright 2011年 __MyCompanyName__. All rights reserved.//#include <stdio.h>#include <limits.h>#include <string.h>#include <time.h>#define BITMASK(b) (1 << ((b) % CHAR_BIT))#define BITSLOT(b) ((b) / CHAR_BIT 阅读全文

posted @ 2011-04-16 01:57 Cheney Shen 阅读(426) 评论(0) 推荐(0) 编辑

导航