mCY mCY - 1 year ago 308
Scala Question

Long/Int in scala to hex string


Integer.toString(1234567, 16).toUpperCase() // output: 12D68
could help to convert an
to Hex string.

How to do the same with Long?

Long.toString(13690566117625, 16).toUpperCase() // but this will report error

Answer Source

You're looking for RichLong.toHexString:

scala> 13690566117625L.toHexString
res0: String = c73955488f9

And the uppercase variant:

scala> 13690566117625L.toHexString.toUpperCase
res1: String = C73955488F9


This also available for Int via RichInt.toHexString:

scala> 42.toHexString
res4: String = 2a
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download