LB Booster
« DECimal to HEXadecimal and XORing »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:29am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
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
BBC BASIC Home Page
Liberty BASIC forum (the original)

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


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 94
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: 210
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: 94
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 »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls