【问题标题】:length of value changes (Java)值变化的长度(Java)
【发布时间】: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


    【解决方案1】:

    在 feedbackValue 和 initialValue 变量的末尾放置一个“L”,以便将其读取为 long。

    【讨论】:

    • 什么?不,这不是问题:)
    猜你喜欢
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    相关资源
    最近更新 更多