Shop OBEX P1 Docs P2 Docs Learn Events
(Debug Based) Binary and Hexadecimal Converter — Parallax Forums

(Debug Based) Binary and Hexadecimal Converter

logan996logan996 Posts: 281
edited 2010-03-08 16:14 in BASIC Stamp
Hi,

· I just finished a program that runs on a regular BS2 Module that can Convert user inputed numbers in to hexadecimal or binary. This is a short program experimenting the BS2's ability to display varibles in another base number system. I've documented each bit of code. NOTE: This program runs completly in the debug terminal!!! (also thanks to this there is no need for any external parts except for the BS2 module itself.)·· Undocumented code below, for documented code download attached BS2 program·

Code
' {$STAMP BS2}
' {$PBASIC 2.5}
orig··· VAR· Word
option· VAR· Nib
DO
·DEBUG CLS
·DEBUG "Convert to Binary or Hexadecimal (binary 1) (hexadecimal 2)"
· DEBUGIN DEC1 option
·IF option = 1 THEN GOTO binary_sub
· IF option = 2 THEN GOTO hexadecimal_sub
·DEBUG "1 will convert to binary, 2 will convert to hexadecimal"
·· LOOP
binary_sub:
·DEBUG CLS
· DEBUG "Enter in Numerals to be converted to Binary "
·· DEBUGIN DEC orig
··· DEBUG "Orignal = ", DEC orig, CR, "Binary = ", BIN orig
···· END
hexadecimal_sub:
·DEBUG CLS
· DEBUG "Enter in Numerals to be converted to Hexadecimal "
·· DEBUGIN DEC orig
··· DEBUG "Orignal = ", DEC orig, CR, "Hexadecimal = ", HEX orig
···· END

Notes:
  • Actulley on the regular BS2 this takes up %26 of the EEPROM
  • the extra space at the end on the· (DEBUG "Enter in Numerals to be converted to Binary ") and·(DEBUG "Enter in Numerals to be converted to Hexadecimal ")·statements are for the ability to backspace before you enter in your number to be converted
  • this can also be used to convert binary and hexadecimal numbers to our (base 10) number system by just entering them in when it asks for the number you want to be converted (like instead of putting "10" in you would put in "1010"



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When the government is afraid of the people there is liberty, when the people are afraid of the government, there is tryanny"

· Thomas Jefferson

Comments

  • logan996logan996 Posts: 281
    edited 2010-03-07 03:22
    Any commets on anything wrong or good or things to make this easier are well appreciated! [noparse]:D[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When the government is afraid of the people there is liberty, when the people are afraid of the government, there is tryanny"

    · Thomas Jefferson
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-03-08 16:14
    This thread is being moved from the Completed Projects Forum to the BASIC Stamp Forum where it is more appropriate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
Sign In or Register to comment.