Converting Hex string (i.e., 0xFF, 0x0AB) to Decimal

Hello,

Is there any fancy command to convert Hex string to Decimal?
I can find some examples but it does not perfectly match with my cases.

My case (with “0x” prefix or sometimes “0” is included between “0x” and the actual value part:
0xFF (hex string) -> 255 (decimal)
0x0AB (hex string) -> 171 (decimal)

The examples I found (no “0x” prefix):
FF -> 255
AB -> 171

If there is no fancy command then what I can do is to remove “0x” or “0x0” from the string and convert.
Thanks.

Hi @uksong -

Welcome to the forum. You can do this using an R Snippet node with just a couple of lines of code, using the R strtoi() function:

Example workflow attached:

2019-09-16%2013_13_35-KNIME%20Analytics%20Platform

2019-09-16%2013_13_44-Data%20Output%20-%205_129%20-%20R%20Snippet

HextoDecimal_RSnippet.knwf (6.0 KB)

4 Likes

Hi @uksong,
and in case you don’t want to use R, you can also use the KNIME column expression with the following snippet:

parseInt(column("YourHexStringColumn"), 16)

Kind regards
Alexander

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.