Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long/Int in scala to hex string

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

How to do the same with Long?

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

like image 683
mCY Avatar asked Sep 15 '16 07:09

mCY


1 Answers

You're looking for RichLong.toHexString:

scala> 13690566117625L.toHexString
res0: String = c73955488f9

And the uppercase variant:

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

Edit

This also available for Int via RichInt.toHexString:

scala> 42.toHexString
res4: String = 2a
like image 193
Yuval Itzchakov Avatar answered Sep 25 '22 18:09

Yuval Itzchakov