zoukankan      html  css  js  c++  java
  • java中的位运算


    public class weiyunsuan {
        
    public static void main(String[] args) {
            
    int a=-6;//          1111 1111 1111 1111 1111 1111 1111 1010
            int b=3;//           0000 0000 0000 0000 0000 0000 0000 0011
            int c=6//          0000 0000 0000 0000 0000 0000 0000 0110
            zuoyi(a, b);//-48    1111 1111 1111 1111 1111 1111 1101 0000
            youyi(a, b);//-1     1111 1111 1111 1111 1111 1111 1111 1111
            wufuhaoyouyi(a, b);//0001 1111 1111 1111 1111 1111 1111 1111
            zuoyi(c, b);//48     0000 0000 0000 0000 0000 0000 0011 0000
            youyi(c, b);//0      0000 0000 0000 0000 0000 0000 0000 0000
            wufuhaoyouyi(c, b);//0000 0000 0000 0000 0000 0000 0000 0000
            yu(a, b);//2         0000 0000 0000 0000 0000 0000 0000 0010
            huo(a, b);//-5       1111 1111 1111 1111 1111 1111 1111 1011
            fei(a);//5           0000 0000 0000 0000 0000 0000 0000 0101
            yihuo(a, b);//-7     1111 1111 1111 1111 1111 1111 1111 1001
        }
        
    public static void zuoyi(int a,int b){
            System.out.println(a
    <<b);
        }
        
    public static void youyi(int a,int b){
            System.out.println(a
    >>b);
        }
        
    public static void wufuhaoyouyi(int a,int b){
            System.out.println(a
    >>>b);
        }
        
    public static void yu(int a,int b){
            System.out.println(a
    &b);
        }
        
    public static void huo(int a,int b){
            System.out.println(a
    |b);
        }
        
    public static void fei(int a){
            System.out.println(
    ~a);
        }
        
    public static void yihuo(int a,int b){
            System.out.println(a
    ^b);
        }
    }

  • 相关阅读:
    在C#中,不安装Oracle客户端如何连接Oracle数据库
    敏捷宣言(四) 猪和鸡的故事
    敏捷宣言(六) 单单有敏捷就够了吗?
    敏捷宣言(五) 看板是另外一种敏捷实践
    敏捷宣言(七) 软件系统
    小白知识摘录__进程和线程
    Linux系统修改/etc/sysconfig/i18n文件,桌面无法正常显示
    小白知识摘录__环境变量
    hive表查询中文显示乱码
    3月10日晚
  • 原文地址:https://www.cnblogs.com/zhonghan/p/1442320.html
Copyright © 2011-2022 走看看