您的位置:首页 > 编程语言 > Java开发

java中的按位与运算

2016-03-26 22:29 471 查看
package scanner;

public class SingleAnd {

public static void main(String[] args) {

int[] first = {10,15,8,5,0};

int[] second = {4,8,1,2};

int result = 0;

for(int i=0; i<first.length; i++){

for(int j=0; j<second.length; j++){

result =  first[i] & second[j];

System.out.println("========================================");

System.out.println(Integer.toBinaryString(first[i]));

System.out.println(Integer.toBinaryString(second[j]));

System.out.println(Integer.toBinaryString(result));

System.out.println(first[i] + "&" + second[j] + "=" + result);

}
}
}
}


运算结果:

========================================
1010
100
0
10&4=0
========================================
1010
1000
1000
10&8=8
========================================
1010
1
0
10&1=0
========================================
1010
10
10
10&2=2
========================================
1111
100
100
15&4=4
========================================
1111
1000
1000
15&8=8
========================================
1111
1
1
15&1=1
========================================
1111
10
10
15&2=2
========================================
1000
100
0
8&4=0
========================================
1000
1000
1000
8&8=8
========================================
1000
1
0
8&1=0
========================================
1000
10
0
8&2=0
========================================
101
100
100
5&4=4
========================================
101
1000
0
5&8=0
========================================
101
1
1
5&1=1
========================================
101
10
0
5&2=0
========================================
0
100
0
0&4=0
========================================
0
1000
0
0&8=0
========================================
0
1
0
0&1=0
========================================
0
10
0
0&2=0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: