これが私の最初の質問です
これが私のコードです:
public class Bits{
public static void main(String args[]){
int i = 2 , j = 4;
int allOnes = ~0;
int left = allOnes << (j+1);
System.out.println("Binary Equivalent at this stage: " +Integer.toBinaryString(left));
}
}
以下は私が得ている出力です:
Binary Equivalent at this stage: 11111111111111111111111111100000
右辺から 8 ビットのみに制限するにはどうすればよいですか。つまり11100000
。
説明してください。
これが私の2番目の質問です:
また、上記の質問とはまったく異なる質問がもう 1 つあります。
public static void main(String args[]){
int i = 2 , j = 4;
int allOnes = ~0; // will equal sequence of all 1s
int left = allOnes << (j+1);
System.out.println("Binary Equivalent at this stage: " +Integer.toBinaryString(left));
}
}
次の行が理解できなかったので:
int allOnes = ~0; // will equal sequence of all 1s
「allOnes」の値を出力しようとすると、「-1」が出力されました。
次のような非常に次の行を理解するのに苦労しています。
int left = allOnes << (j+1);