Oxygen Basic
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Latest OxygenBasic.zip at GitHub
(Click on the Wizard)
Home
Help
Search
Login
Register
Oxygen Basic
»
Programming
»
Problems & Solutions
»
ATH HTA
« previous
next »
Print
Pages: [
1
]
Author
Topic: ATH HTA (Read 979 times)
0 Members and 1 Guest are viewing this topic.
JRS
Guest
ATH HTA
«
on:
May 02, 2018, 10:28:50 PM »
Code: OxygenBasic
'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
A couple of similar functions I translated to Script BASIC from Business BASIC.
Code: Script BASIC
FUNCTION
BB_ATH(HexStr)
LOCAL
LenHex, AsciiStr, HexTable, ScanPos, HiByte, LowByte
LenHex =
LEN
(HexStr)
IF
LenHex % 2 = 0
THEN
HexTable =
"0123456789ABCDEF"
FOR
ScanPos = 1
TO
LenHex
STEP
2
HiByte =
INSTR
(HexTable,
UCASE
(
MID
(HexStr, ScanPos, 1))) - 1
LowByte =
INSTR
(HexTable,
UCASE
(
MID
(HexStr, ScanPos + 1, 1))) - 1
IF
ISINTEGER
(HiByte)
AND
ISINTEGER
(LowByte)
THEN
AsciiStr &=
CHR
(HiByte * 16 + LowByte)
ELSE
AsciiStr =
""
GOTO
Exit_For
END
IF
NEXT
ScanPos
Exit_For:
ELSE
AsciiStr =
""
END
IF
BB_ATH = AsciiStr
END
FUNCTION
FUNCTION
BB_HTA(AsciiStr)
LOCAL
AsciiLen,ScanPos,HexStr
AsciiLen =
LEN
(AsciiStr)
IF
AsciiLen
THEN
FOR
ScanPos = 1
TO
AsciiLen
HexStr &=
RIGHT
(
"0"
&
HEX
(
ASC
(
MID
(AsciiStr, ScanPos, 1))),2)
NEXT
ScanPos
ELSE
HexStr =
""
END
IF
BB_HTA = HexStr
END
FUNCTION
hstr = BB_HTA(
"0123456789ABCDEF"
)
PRINT
hstr,
"\n"
PRINT
BB_ATH(hstr),
"\n"
jrs@jrs-laptop:~/sb/examples/test$ scriba a2hh2a.sb
30313233343536373839414243444546
0123456789ABCDEF
jrs@jrs-laptop:~/sb/examples/test$
Logged
Print
Pages: [
1
]
« previous
next »
Oxygen Basic
»
Programming
»
Problems & Solutions
»
ATH HTA