이진수에서 1의 개수 세기
이진수에서 1의 개수 세기
and연산을 이용하여 이진수의 1의 개수를 구할 수 있다.
java 코드
public int countOneBit(int value){
int i;
for(i = 0; value != 0; i++)
{
value &= (value - 1);
}
return i;
}
참고사이트: https://kylog.tistory.com/6
and연산을 이용하여 이진수의 1의 개수를 구할 수 있다.
public int countOneBit(int value){
int i;
for(i = 0; value != 0; i++)
{
value &= (value - 1);
}
return i;
}
참고사이트: https://kylog.tistory.com/6