c语言整数转二进制显示及统计1的个数


#include "stdio.h" 
#include "stdlib.h" 
#include "string.h"
 
int main(void){
	int in_int;
	printf("请输入一个整数:"); 
	scanf("%d", &in_int); 
	
	//printf("输入的整数:%d\n", c); 

	char buf[100]={0};	
	int len = 0;
	int ci = in_int;
	int times1 = 0;  //二进制串中1的个数
	do{
		int b = ci & 1; 
		buf[len++] = b + '0';
		if(b > 0){ times1++;} 
		ci = ci>>1; 
	}while(ci > 0); 

	int i,len2 = len/2;

	//printf("c=%d, len=%d, len2=%d,  str=%s\n", c,len, len2,buf); 
	//反转字符串
	for(i=0; i


你可能感兴趣的:(c++)