Skip to content Skip to sidebar Skip to footer

Presto - Hex String To Int

I'm trying to convert hex string (starts with '0x') to it's integer value using presto. For example 0x100 to 256. My hex string is called msg_id. I tried to use this- from_hex(su

Solution 1:

You can use from_base(string, radix) to parse number written with hex digits into a bigint. You just need to strip leading '0x' first:

selectfrom_base(substr('0x100', 3), 16);
 _col0
-------
   256

or with regexp_replace():

presto:tiny> select from_base(regexp_replace('0x100', '^0x'), 16);
 _col0
-------
   256

Post a Comment for "Presto - Hex String To Int"