移位操作符

如下是一个关于移位操作符的代码,谁能帮忙解释下:
public class URShift {

public static void main(String[] args) {
int i = -1;
printBinaryInt("i", i);
printBinaryInt("i >>>= 10", i >>>= 10);
long l = -1;
printBinaryLong("l", l);
printBinaryLong("l >>>= 10", l >>>= 10);
short s = -1;
printBinaryShort("s", s);
printBinaryShort("s >>>= 17", s >>>= 17);
s = -1;
printBinaryShort("s", s);
printBinaryInt("s >>>17", s >>> 17);
byte b = -1;
printBinaryByte("b", b);
printBinaryByte("b >>>= 25", b >>>= 25);
b = -1;
printBinaryByte("b", b);
printBinaryInt("b>>>25", b >>> 25);

}

static void printBinaryByte(String s, byte i) {
System.out.println(s + ", byte: " + i + ", binary: ");
System.out.print(" ");
for (int j = 7; j >= 0; j--)
if (((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}

static void printBinaryShort(String s, short i) {
System.out.println(s + ", short: " + i + ", binary: ");
System.out.print(" ");
for (int j = 15; j >= 0; j--)
if (((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}

static void printBinaryInt(String s, int i) {
System.out.println(s + ", int: " + i + ", binary: ");
System.out.print(" ");
for (int j = 31; j >= 0; j--)
if (((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}

static void printBinaryLong(String s, long l) {
System.out.println(s + ", long: " + l + ", binary: ");
System.out.print(" ");
for (int i = 63; i >= 0; i--)
if (((1L << i) & l) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();

}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值