1. How to convert to and from HEX?
- Posted by tonysteward May 31, 2013
- 1156 views
I am able to convert a sequence to hex for storage in a bin file but how do I convert it back?
As in if I have a sequence "12" and pass that through th following function I get the desired result. But how can I convert that back again
function HToI(sequence Hex) -- convert hexadecimal string to integer integer n n = 0 for i = 1 to length(Hex) do if Hex[i] >='A' then n = n * 16 + Hex[i] - 'A' + 10 else n = n * 16 + Hex[i] - '0' end if end for return n end function
2. Re: How to convert to and from HEX?
- Posted by mattlewis (admin) May 31, 2013
- 1205 views
tonysteward said...
I am able to convert a sequence to hex for storage in a bin file but how do I convert it back?
As in if I have a sequence "12" and pass that through th following function I get the desired result. But how can I convert that back again
Use %x inside of printf / sprintf:
printf(1, "18 = #%x\n", 18)
Matt
3. Re: How to convert to and from HEX?
- Posted by DerekParnell (admin) May 31, 2013
- 1071 views
tonysteward said...
I am able to convert a sequence to hex for storage in a bin file but how do I convert it back?
There is a function in std/text.e for this.
include std/text.e sequence Result Result = format("[X]", 54321) --> Returns "D431"