如何将整数类型转换为无符号类型?我用Java编码

时间:2015-10-27 15:28:19

标签: java

例如:

public static void main(String[] args) { 
    String str = "11111111111111111111111111111111";
    int a = Integer.parseUnsignedInt(str, 2);
    System.out.println(a);
}`

结果:-1 但是unsigned int类型的范围是0~2 ^ 32 - 1?

1 个答案:

答案 0 :(得分:0)

试试这个,将你的int传递给这个函数

  public static long getUnsignedInt(int x) {
        return x & 0x00000000ffffffffL;
    }