Simon
Simon

Reputation: 143

Pull out 64 bit number from Hex using Java

I hope this makes sense. When I use a Hex editor and hover over a hex value you can see a 8, 16, 32 and 64 bit number (see screen shot for better idea)

http://www.facebook.com/photo.php?pid=2298915&l=e45630aead&id=1283154964 http://a5.sphotos.ak.fbcdn.net/hphotos-ak-snc6/189710_1899804496495_1283154964_2298915_5950535_n.jpg

Is there a way to pull that number out using Java, I need to pull the 64bit number out I don't know if this is possible?

If any one knows I would be very greatful!

Many thanks in advance.

Upvotes: 2

Views: 2890

Answers (1)

corsiKa
corsiKa

Reputation: 82589

If you have a string of HEX that you want to convert to a 64 bit number, you can use

long asHex = Long.parseLong(theHexValue,16); // 16 denotes as hex

This will produce a SIGNED long value. If you're looking for > 2^63, you need to use BigInteger

BigInteger asHex = new BigInteger(theHexValue,16);

Upvotes: 1

Related Questions