convert decimal to binary
antonis
Posts: 9
hello,
i have a variable in my program and the number where it takes is in decimal format can i create a same variable and convert the first variable data in binary
example:
first VAR BYTE
second VAR BYTE
'===========program===========================
initialize:
first=0
second=0
main:
IF IN1=1 THEN increase
IF IN0=1 THEN decrease
IF IN2=1 THEN binary
GOTO main
'===============routines==========================
increase:
first=first+1
DEBUG DEC first
PAUSE 1000
GOTO main
decrease:
first=first-1
DEBUG DEC first
PAUSE 1000
GOTO main
binary:
second = ?????????????????? (i wan't store in that variable data of FIRST in binary format)
DEBUG BIN second
GOTO main
i have a variable in my program and the number where it takes is in decimal format can i create a same variable and convert the first variable data in binary
example:
first VAR BYTE
second VAR BYTE
'===========program===========================
initialize:
first=0
second=0
main:
IF IN1=1 THEN increase
IF IN0=1 THEN decrease
IF IN2=1 THEN binary
GOTO main
'===============routines==========================
increase:
first=first+1
DEBUG DEC first
PAUSE 1000
GOTO main
decrease:
first=first-1
DEBUG DEC first
PAUSE 1000
GOTO main
binary:
second = ?????????????????? (i wan't store in that variable data of FIRST in binary format)
DEBUG BIN second
GOTO main
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
DEBUG DEC fisrt
DEBUG BIN first
And you would see the same value in both formats. Add the following line and you can see it in HEX as well.
DEBUG HEX first
One final note...to align the digits you may want to add a number follow the DEC, BIN and HEX formatters so the values don't shift as they decrease causing old values to still be on the screen when the number gets smaller.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·