LB Booster
« DECimal to HEXadecimal and XORing »

Welcome Guest. Please Login or Register.
Jul 26th, 2017, 10:43am


Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
LB Umbrella forum
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: DECimal to HEXadecimal and XORing  (Read 27 times)
flotulopex
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 81
xx DECimal to HEXadecimal and XORing
« Thread started on: Jul 16th, 2017, 9:46pm »

Hi,

I need to convert a DECimal value into a HEXadecimal and do some XORing for CheckSum calculation.

I don't find how to convert the DECValue to a HEX value and append it to the XORing line calculation.

Any help please?

Code:
' DEC to HEX and XORing

DECValue = 0
Data$    = ""
CheckSum = 0

'message to be sent (serial): "94 10 00 nn xx"
'  94 10 00        = header
'           nn     = entered value
'              xx  = CheckSum


NOMAINWIN

[MAIN]

   TEXTBOX    #Main.TBx10,                            30, 30, 30, 20
   BUTTON     #Main.Btn10,"Calculate",[Calculate],UL,115, 30, 60, 22

   OPEN "DEC to HEX and XORing" FOR window AS #Main
   #Main "TRAPCLOSE [QUIT]"
   WAIT

[Calculate] ' message example where DECValue is 20 = "94 10 00 14 90"
   #Main.TBx10, "!contents? DECValue"

   CS = &H94 XOR &H10 XOR &H00 XOR &H14

   Data$ = "94 10 00 " + DECHEX$(DECValue) + " " + DECHEX$(CS)
   
   NOTICE "Result" + CHR$(13) + Data$
   WAIT

[QUIT]
   CLOSE #Main
   END 
User IP Logged

Roger
tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 196
xx Re: DECimal to HEXadecimal and XORing
« Reply #1 on: Jul 17th, 2017, 06:42am »

Quote:
I don't find how to convert the DECValue to a HEX value and append it to the XORing line calculation.

You don't.
XOR works on numbers - so just put DECValue
HEX values (after DECHEX$()) are actually strings.

So
Code:
 CS = &H94 XOR &H10 XOR &H00 XOR DECValue 
 
User IP Logged

flotulopex
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 81
xx Re: DECimal to HEXadecimal and XORing
« Reply #2 on: Jul 17th, 2017, 4:37pm »

Thank you very much.

smiley
User IP Logged

Roger
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls