bryan1
Well-Known Member
This thread will deal with code snippets for the Oshonsoft Basic Compiler and is a normal thread for members to add code snippets and other members are free to ask questions. When a member puts code snippets in this thread I can move them into the sticky which is locked to prevent unneeded posts not directly dealing with snippets.
To convert a binary value from 0x001 to 0x270f to 0001 to 9999 decimal
Regards Bryan
To convert a binary value from 0x001 to 0x270f to 0001 to 9999 decimal
Code:
Dim ascbfr3 As Byte 'used in convert routing
Dim ascbfr2 As Byte 'used in convert routing
Dim ascbfr1 As Byte 'used in convert routine
Dim ascbfr0 As Byte 'used in convert routine
binval = volts
Gosub bin2asc
bin2asc:
ascbfr3 = binval / 1000
temp3 = binval Mod 1000
ascbfr2 = temp3 / 100
temp3 = temp3 Mod 100
ascbfr1 = temp3 / 10
ascbfr0 = temp3 Mod 10
'results are BCD so
'convert to ASCII for LCD
ascbfr3 = ascbfr3 Or 0x30
ascbfr2 = ascbfr2 Or 0x30
ascbfr1 = ascbfr1 Or 0x30
ascbfr0 = ascbfr0 Or 0
' and to show on a lcd after it is set up
Lcdout "Volts:", ascbfr3, ascbfr2, ".", ascbfr1, ascbfr0
'this will put a decimal point in and the example shows a voltage reading to 2 decimal places
Regards Bryan
Last edited: