Shop OBEX P1 Docs P2 Docs Learn Events
convert decimal to binary — Parallax Forums

convert decimal to binary

antonisantonis Posts: 9
edited 2010-06-08 21:59 in BASIC Stamp
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

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-06-08 18:45
    All data in the stamp is binary only how it is read by humans is different. second = first should work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-06-08 20:11
    Exactly...so you could have said:

    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
    ·
  • antonisantonis Posts: 9
    edited 2010-06-08 21:59
    thanks
Sign In or Register to comment.