• Welcome to Jose's Read Only Forum 2023.
 

Clean StringToHex and HextToString

Started by Charles Pegge, May 02, 2018, 04:13:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

Hi Chris,

No aggro from Windows 10 Defender with these functions :)


'2018-05-02 T 15:07:27
%filename "t.exe"
uses rtl64
uses corewin

function StringToHex(string s) as string
========================================
int le=len s
int i,j
string r=nuls le*2
indexbase 1
for i=1 to le
  j++
  mid r,j,hex(asc(s,i),2)
  j++
next
return r
end function


function HexToString(string s) as string
========================================
int le=len s
int i,j
string r=nuls le\2
byte rb at strptr r
indexbase 1
for i=1 to le step 2
  j++
  rb[j]=val "0x"+mid(s,i,2)
next
return r
end function

'TEST
'====
string h=StringToHex "ABCDEF"
string s=HexToString h
print h
print s

Chris Chancellor

Thanxx a lot Charles

what was the problem with the previous program?

as the Windows Defender smartscreen
will block the compile exe from running with the message

   "This app can't run on your PC" 


Charles Pegge

I didn't attempt to find out, Chris. A straight rewrite is often the easiest. Watch out for overflows.