LB Booster
Programming >> Liberty BASIC language >> DECimal to HEXadecimal and XORing
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1500241569

DECimal to HEXadecimal and XORing
Post by flotulopex 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 

Re: DECimal to HEXadecimal and XORing
Post by tsh73 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 
 

Re: DECimal to HEXadecimal and XORing
Post by flotulopex on Jul 17th, 2017, 4:37pm

Thank you very much.

smiley