Best way to convert a signed integer to an unsigned long?

后端 未结 7 1404
清酒与你
清酒与你 2020-11-28 06:25

For certain hash functions in Java it would be nice to see the value as an unsigned integer (e.g. for comparison to other implementations) but Java supports only signed type

相关标签:
7条回答
  • 2020-11-28 07:09

    other solution.

    public static long getUnsignedInt(int x) {
        if(x > 0) return x;
        long res = (long)(Math.pow(2, 32)) + x;
        return res;
    }
    
    0 讨论(0)
提交回复
热议问题