我需要二进制的int 32,就像二进制0111 1111中的00100000或int 127。变体Integer.toBinaryString只返回1的结果。如果以这种方式构建for循环:
for (int i= 32; i <= 127; i + +) {
System.out.println (i); 
System.out.println (Integer.toBinaryString (i));
}从二进制数来看,我需要前导零(计数前导零)或前导零数(Nlz)的数目,我实际上是指0的确切数字,例如:在00100000 -> 2和0111111->1。
发布于 2014-01-25 13:33:50
怎么样
int lz = Integer.numberOfLeadingZeros(i & 0xFF) - 24;
int tz = Integer.numberOfLeadingZeros(i | 0x100); // max is 8.https://stackoverflow.com/questions/21350827
复制相似问题