【发布时间】:2017-12-07 07:50:54
【问题描述】:
我目前正在编写一个使用十六进制值的代码。出于某种原因,在程序期间,十六进制值从 32 位长值变为 64 位长值。任何人都可以提供有关为什么会发生这种情况的见解吗?
final private long feedbackValue = 0x87654321;
private long state;
public void initialize(long initialValue) {
int count = 0;
state = feedbackValue ^ initialValue;
System.out.println("State "+count+":"+ String.format("0x%08X",state));
while (count < 8) {
update();
count++;
System.out.println("State "+count+":"+ String.format("0x%08x",state));
}
}//end initialize method
private void update() {
if ((state & 1) == 0) {
state = state >>> 1;
} else {
state = (state >>> 1)^feedbackValue;
}
}//end update method
当initialValue = 0xffffffff时,结果如下:
State 0:0x789ABCDE
State 1:0x3c4d5e6f
State 2:0xffffffff9943ec16
State 3:0x7fffffffcca1f60b
State 4:0xc00000006135b824
State 5:0x60000000309adc12
State 6:0x30000000184d6e09
State 7:0xe7ffffff8b43f425
State 8:0x8c00000042c4b933
【问题讨论】:
标签: java hex bit-manipulation bitwise-operators