zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    反射&异常
    成员方法
    继承&多态
    面向对象
    常用模块
    软件目录结构规范
    内置函数
    生产器&迭代器
    装饰器
    函数
  • 原文地址:https://www.cnblogs.com/haimishasha/p/5324324.html
Copyright © 2011-2022 走看看