int a=0xFFFF;
System.out.println("test1 "+Integer.toBinaryString(a));
a<<=1;
System.out.println("test2 "+Integer.toBinaryString(a));
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)Output: test1 1111111111111111 test2 11111111111111110
我的问题是,它0来自哪里?
有在返回没有前导零String的Integer.toBinaryString.有16 1秒0xFFFF,但也有16 0秒.
00000000 00000000 11111111 11111111 // 16 printed
Run Code Online (Sandbox Code Playgroud)
然后左移1为零显着.
00000000 00000001 11111111 11111110 // 17 printed
Run Code Online (Sandbox Code Playgroud)
该值转换为二进制(基数2)中的ASCII数字字符串,没有额外的前导0.
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |