1 packagescanner;2
3 public classSingleAnd {4
5 public static voidmain(String[] args) {6
7 int[] first = {10,15,8,5,0};8
9 int[] second = {4,8,1,2};10
11 int result = 0;12
13 for(int i=0; i
15 for(int j=0; j
17 result = first[i] &second[j];18
19 System.out.println("========================================");20
21 System.out.println(Integer.toBinaryString(first[i]));22
23 System.out.println(Integer.toBinaryString(second[j]));24
25 System.out.println(Integer.toBinaryString(result));26
27 System.out.println(first[i] + "&" + second[j] + "=" +result);28
29
30 }31 }32 }33 }
运算结果:
========================================
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
原文:http://www.cnblogs.com/haimishasha/p/5324324.html
该篇博客展示了如何使用Java进行位运算,特别是按位与操作。通过示例代码,解释了如何对两个整数数组的对应元素进行位与运算,并打印出二进制和运算结果,帮助理解位操作在编程中的应用。
797

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



