0

for example:

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

result:-1 but doesn't the range of unsigned int type is 0~2^32 - 1?

Barry Bao
  • 29
  • 5
  • Look at [this](http://stackoverflow.com/questions/9578639/best-way-to-convert-a-signed-integer-to-an-unsigned-long)! It's an old question from stackoverflow – Paolo Zaia Oct 27 '15 at 15:33
  • Possible duplicate of http://stackoverflow.com/questions/9578639/best-way-to-convert-a-signed-integer-to-an-unsigned-long – Perdomoff Oct 27 '15 at 15:34
  • 1
    Signedness is only in your mind. It's just bits after bits. – Kayaman Oct 27 '15 at 16:02

1 Answers1

0

try this, pass in your int to this function

  public static long getUnsignedInt(int x) {
        return x & 0x00000000ffffffffL;
    }
AbtPst
  • 7,778
  • 17
  • 91
  • 172