package com.patience.interview.huawei;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* 求int型正整数在内存中存储时1的个数
* @author Green.Gee
* @date 2022/8/1 10:11
* @email green.gee.lu@gmail.com
*/
public class GetBinaryCount {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String input = bf.readLine();
Integer max = Integer.valueOf(input);//2147483647
String binaryStr = Integer.toBinaryString(max);
int count = 0;
for(char c : binaryStr.toCharArray()){
if(c == '1')
count++;
}
System.out.println(count);
}
}
求int型正整数在内存中存储时1的个数
最新推荐文章于 2024-09-04 15:29:36 发布