AIRecomandationTest from niuke bitscount
package com.microsoft.aiRecmandation;
import java.util.ArrayList;
import java.util.List;
public class AIRecomandationTestController {
public static void main(String[] args) {
System.out.println("Hello World!");
}
// from niuke test .com bitscount
/**
* int型正整数在内存中存储时1的个数
* @param srcInt
* @return
*/
public static Integer getBinaryNumCnt(Integer srcInt){
if (srcInt==null){
return null;
}
List<Integer> integerArrayList = new ArrayList<>();
while (true){
int modeRet=srcInt % 2;
integerArrayList.add(modeRet);
srcInt /= 2;
if (srcInt==0){
break;
}
}
List<Integer> arrayList = new ArrayList<>();
integerArrayList.forEach(e->{
if (e==1){
arrayList.add(e);
}
});
return arrayList.size();
}
// positive int num to binarybits
public static String BigDecimal2BinaryBits(int bigDecimalInt) {
if(bigDecimalInt<0) {
return null;
}
// 2to0 2to1 2to2 2to3 1 2 4 8 decimal number represention
// 10=1+2+4+3(1+2 00010010000000 decimal 3=2+1) 00000110000000000000000000 decimal = 1+2+4+(1+2)->7+3=10
// bits2BigDecimal 2to0+2to2 (1+2) 4 +
StringBuilder strBuilder=new StringBuilder();
int count=0;
while(true) {
int overBits=bigDecimalInt/2;
int overBitLessBits=overBits%2;
// over bits less come to end break this roopS
strBuilder.add();
if(overBitLessBits==count) {
break;
}
count++;
}
return strBuilder.toString();
}
}
Java技术 文章被收录于专栏
JavaEE技术 编程开发经验 企业通用技术
查看4道真题和解析