Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Charles Pegge on May 02, 2018, 04:13:43 PM

Title: Clean StringToHex and HextToString
Post by: Charles Pegge on May 02, 2018, 04:13:43 PM
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
Title: Re: Clean StringToHex and HextToString
Post by: Chris Chancellor on May 02, 2018, 04:51:52 PM
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" 

Title: Re: Clean StringToHex and HextToString
Post by: Charles Pegge on May 02, 2018, 07:01:55 PM
I didn't attempt to find out, Chris. A straight rewrite is often the easiest. Watch out for overflows.