簡體   English   中英

移位位,它是從哪里來的?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM