public class BytesToInt { public static int count1(int value){ int count = 0; for (int i = 0; i < 32; i++){ if ((value & 0x01) == 0x01){ count++; } value = value >> 1; } return count; } public static void main(String[] args) { System.out.println(count1(0xff)); // 8 } }参考博客: http://www.cnblogs.com/xiangxiaodong/archive/2012/10/20/2732666.html