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);
        }
    }

  • 相关阅读:
    Vpython简单例子
    我在读的书:《ACM图灵奖:19662006(第三版)计算机发展史的缩影》
    可惜啊,没见到姚期智~~
    The Sounds of Music 观后感
    终于在博客园申请开通博客了
    【引用】Python open读写文件实现脚本
    在Python中使用中文
    Discovery:深入理解计算机系统 (Ver.2) 中文版
    [导入]一个都不能少:全面认识IE插件
    [导入]午间心情
  • 原文地址:https://www.cnblogs.com/zhonghan/p/1442320.html
Copyright © 2011-2022 走看看