Here you can find the source of bitCount(byte b)
Parameter | Description |
---|---|
b | the byte on which we compute the hamming distance with 0 |
public static short bitCount(byte b)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a va2 s.c o m * Hamming distance of a byte with 0 * @param b the byte on which we compute the hamming distance with 0 * @return the number of 1's in the binary representation of the byte */ public static short bitCount(byte b) { short temp = (short) (b + 128); short count = 0; for (int i = 0; i < 8; i++) { count += (temp >> (7 - i)) % 2; } return count; } }