[英]Shifting bits, where did it came from?
int a=0xFFFF;
System.out.println("test1 "+Integer.toBinaryString(a));
a<<=1;
System.out.println("test2 "+Integer.toBinaryString(a));
Output: test1 1111111111111111 test2 11111111111111110
我的問題是, 0
是從哪里來的?
從Integer.toBinaryString
返回的String
中沒有前導零。 0xFFFF
有16 1
s,但也有16 0
s。
00000000 00000000 11111111 11111111 // 16 printed
然后左移1表示零。
00000000 00000001 11111111 11111110 // 17 printed
此值將轉換為二進制(以2為底)的ASCII數字字符串, 且沒有多余的前導0 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.