Convert Hex to Decimal

Trying to convert a hexadecimal value to a decimal value. I am able to do this conversion using the “format(“%d”, )”. That works IF it’s a number, but unfortunately the value is obtained from the SUT & eggPlant interprets as text. Trying to explicitly convert the obtained text prior to calling format yields errors too [eg. asNumber()].

This works:
Set decValue = format(“%d”, 0x000006A9)

This errors “is not a number:”
Set decValue = format(“%d”, eggPlant function to obtain value from SUT)

Any thoughts on best way to do this without writing a hex to dec converter?

Thanks!

You can convert the string to its numeric value using the value() function:

put value("0x000006A9") into somevar
Set decValue = format("%d", somevar)
put decValue // outputs 1705

Perfect. Thanks Matt.

I’d just add that the format() function isn’t needed in this case. It used to be the recommended (well, really the only) way to convert in the other direction, to get the hex representation of a number. Now, you can just say “as hex”:

put 79 as hex
--> 0x4F

Or in keeping with the example:

put value("0x000006A9") into somevar
put somevar as a number
--> 1705