java中的按位与运算

 1 package scanner;
 2 
 3 public class SingleAnd {
 4     
 5     public static void main(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<first.length; i++){
14             
15             for(int j=0; j<second.length; j++){
16                 
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值