lxw
2023-12-23 26576e9f9457467e6d6dbf037fba3f7235e7f38d
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
26
27
28
29
30
31
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,int[] bit){
        int count=0;
        /*int ss=switchState&(1<<bit);
        while (ss != 0){
            ss = ss & (ss - 1);
            count++;
        }*/
        if(bit.length>0){
            for (int i=0;i<bit.length;i++){
                int ss=switchState&(1<<bit[i]);
                if(ss>0){
                    count++;
                }
            }
        }
        return count;
    }
 
    public static void main(String[] args) {
        System.out.println(getIntToBinary(15,new int[]{0,1,2,3}));
    }
}