⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l41.1a

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 1A
字号:
#printThe problem is to produce a function	bitct(x)which examines the bits in x, returning a count ofthe number of 1-bits.  There are various ways of doingthis job: here are two.(1) a sane way.  Shift the word x right 16 times (you areon UNIX) and check the rightmost bit each time, countingthe number of times it is '1'.(2) a machine-independent (sort of) way.  The logicalbitwise AND of x and x-1 contains one fewer one bit than x itself.Loop anding x and x-1 until you get zero.Program either algorithm.  Compile and test it.  Leave it ona file bitct.c and type "ready".#once #create tzaqc.cmain(){	int x;	x=23069;	if (bitct(x) != goodct(x)) 		return(1);	x=0;	if (bitct(x) != goodct(x)) 		return(1);	x=16384;	if (bitct(x) != goodct(x)) 		return(1);	x = -1;	if (bitct(x) != goodct(x)) 		return(1);	x= -200;	if (bitct(x) != goodct(x)) 		return(1);	return(0);}goodct(x){	int k, i;	for(k=i=0; i<16; i++)		{		k =+ (x&1);		x= x>>1;		}	return(k);}#usercc tzaqc.c bitct.oa.out#succeed/*  a possible solution */bitct(x){	int k, i;	for(i=k=0; i<16; i++) {		if (x&1)			k++;		x >>= 1;	}	return(k);}/* by the way, if you really care aboutthis problem a table lookup by whole bytesis faster */#log#next42.1a 10

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -