1. How to convert to and from HEX?

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 
new topic     » topic index » view message » categorize

2. Re: How to convert to and from HEX?

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: How to convert to and from HEX?

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" 
 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu