whycxzp
2023-12-23 e2e4743c2ed9fc33ada243a7a760951f2eeaa07c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.whyc.util;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
 
public class CommonUtil {
 
    //将数转换成二进制字符串并统计1的个数
    public static int getIntToBinary(int switchState){
        /*String binaryString=Integer.toBinaryString(switchState);
        System.out.println(binaryString);*/
        int count=0;
        while (switchState != 0){
            switchState = switchState & (switchState - 1);
            count++;
        }
        //System.out.println(count);
        return count;
    }
 
    public static void main(String[] args) {
        getIntToBinary(111111024);
    }
}