package cn.Text; public class text1 { public static void main(String[] args) { int num=888; print(num); //测试 左移 二进制数:00000000000000000000000000000010 2 int test=1; print(test); print(test<<1); print(test<<2); print(test<<8); //测试 右移 System.out.println("********"); int e=1024; int f=Integer.MIN_VALUE; print(e); print(f); // 10000000000000000000000000000000 print(e>>1); print(f>>2);// 11000000000000000000000000000000 TODO >> 符号位 “1” 来补 print(f>>>1);// 01000000000000000000000000000000 TODO >>> "0" 来补 // TODO -2^31 ~ 2^31 -1 int a=Integer.MAX_VALUE; int b=Integer.MIN_VALUE; System.out.println(a); System.out.println(b); print(a); // -3 -5二进制数 // TODO 负数,第一位是符号位 32位 10000......000 表示负数,取反加1 print(-3); //11111111111111111111111111111101 TODO 符号位不变,其余取反 00000000000000000000000000000010 加1 00000000000000000000000000000011 print(-5); //11111111111111111111111111111011 //放飞自我 int c=21183578; int d=999834; print(c); print(d); System.out.println("============="); print(c|d); print(c&d); print(c^d); //相反数 int g=5; int h=-g; int k=(~g+1); System.out.println(g); System.out.println(h); System.out.println(k); } public static void print(int num){ for (int i = 31; i >=0; i--) { System.out.print((num&(1<<i))==0?"0":"1"); } System.out.println(); } }
"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:S:\jdk\IntelliJ IDEA Community Edition 2021.3\lib\idea_rt.jar=52057:S:\jdk\IntelliJ IDEA Community Edition 2021.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;C:\Users\17331\IdeaProjects\order\out\production\order" cn.Text.text1 00000000000000000000001101111000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000100 00000000000000000000000100000000 ******** 00000000000000000000010000000000 10000000000000000000000000000000 00000000000000000000001000000000 11100000000000000000000000000000 01000000000000000000000000000000 2147483647 -2147483648 01111111111111111111111111111111 11111111111111111111111111111101 11111111111111111111111111111011 00000001010000110011110001011010 00000000000011110100000110011010 ============= 00000001010011110111110111011010 00000000000000110000000000011010 00000001010011000111110111000000 5 -5 -5 Process finished with exit code 0
上面是java的,下面是python的,代码执行不一样,理论一样