20070821 Tuesday August 21, 2007

Unsigned long in Java

I needed to get the unsigned value of the bytes in a long. Took some digging, but this finally worked for me:

long longValue;
...// set longValue to something
BigInteger bi = new BigInteger(
    Long.toHexString(longValue),16
);

You can then use the methods on BigInteger to get your value. I needed the raw unsigned bytes, so I called bi.toByteArray().

Posted by rickg ( Aug 21 2007, 06:12:23 AM PDT ) Permalink Comments [1]