二进制运算 移位运算

来源:互联网 发布:淘梦网络 编辑:程序博客网 时间:2024/06/08 08:07
/** * 作者: * 日期:2013-11-16 * 功能:移位运算,二进制算法 */package com.cg;public class Demo1 {public static void main(String[] args) {//~取反 0变1 1变0 包括符号位的变化System.out.println("~2="+(~2));//&与运算 同为1才为1System.out.println("2&3="+(2&3));//|或运算 有1便是1System.out.println("2|3="+(2|3));//~取反 0变1 1变0 包括符号位的变化System.out.println("~-5="+(~-5));//^异或 不同便取1System.out.println("-3^3="+(-3^3));//算术右移 低位溢出 符号位不变 并用符号位补溢出的高位System.out.println("1>>2="+(1>>2));System.out.println("-1>>2="+(-1>>2));//算术左移 符号位不变,低位补0System.out.println("1<<2="+(1<<2));//逻辑右移 低位溢出 高位补0System.out.println("1>>>2="+(1>>>2));}}

原创粉丝点击