【问题标题】:How to convert an integer type to an unsigned type?I'm coding in Java如何将整数类型转换为无符号类型?我正在用 Java 编码
【发布时间】:2015-10-27 15:28:18
【问题描述】:

例如:

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吗?

【问题讨论】:

标签: java


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多