一、演算位运算
public class IntToBinary {
public static void main(String[] args) throws UnsupportedEncodingException {
int data = 4;
System.out.println("the 4 is "+Integer.toBinaryString(data));
//位与 &(1&1=1 1&0=0 0&0=0)
System.out.println("the 4 is "+Integer.toBinaryString(4));
System.out.println("the 6 is "+Integer.toBinaryString(6));
System.out.println("the 4&6 is "+Integer.toBinaryString(4&6));
//位或 | (1|1=1 1|0=1 0|0=0)
System.out.println("the 4|6 is "+Integer.toBinaryString(4|6));
//位非~(~1=0 ~0=1)
System.out.println("the ~4 is "+Integer.toBinaryString(~4));
//位异或 ^ (1^1=0 1^0=1 0^0=0)
System.out.println("the 4^6 is "+Integer.toBinaryString(4^6));
// <<有符号左移 >>有符号的右移 >>>无符号右移
//取模的操作 a % (2^n) 等价于 a&(2^n-1)
System.out.println("the 345 % 16 is "+(345%16)+ " or "+(345&(16-1

本文探讨了位运算在电商权限设置中的使用,通过具体的位运算实例展示如何进行权限控制,同时指出这种技术也可应用于商品多属性的判断,有效减少数据库字段存储。
最低0.47元/天 解锁文章
171万+

被折叠的 条评论
为什么被折叠?



