Convert unsigned int to long in Java
Use Integer.toUnsignedLong
to avoid sign extension.
int i = 0b10000011001000010101011000000000; // -2094967296 or 2200000000
long signed = i; // -2094967296 (with sign extension)
long unsigned = Integer.toUnsignedLong(i); // 2200000000 (without sign extension)
Or, equivalently:
long unsigned = i & 0xffffffffL;
Comments
Be the first to comment!