Shop OBEX P1 Docs P2 Docs Learn Events
Bs2 Need to know how to display a character as a number — Parallax Forums

Bs2 Need to know how to display a character as a number

StatzStatz Posts: 28
edited 2008-11-29 00:08 in BASIC Stamp
jumpin.gif just need to convert a to 97 and so on and so forth. How would I go about display these values in ascii

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-27 22:24
    You need to be clearer about what you want. ASCII is a coding for characters. That means that the binary (numeric) values stored in memory correspond to displayed characters. If you have 97 in a location in memory, it will be displayed as "a". If you have an ASCII keyboard, the key marked "a" will be represented in the computer as 97. Do you mean that you want the contents of a location in memory to be displayed as a string of digits giving the value of the location in decimal? If you're using a Stamp I/O statement like DEBUG, SEROUT or LCDOUT, the "formatter"s will do that for you. Read the Manual's description of DEC or HEX or BIN for details, but "DEBUG DEC X" will output the contents of X as a string of digits to the debug window.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-27 22:31
    A VAR byte

    A = "a"

    debug dec A·· ' This will display the number 97




    That is, it's already 97.· No conversion needed.· The decimal number 97, and the character "a", are just different names for the same arrangement of ones and zeros in an eight-bit byte.

    Before someone jumps on me for saying "eight-bit byte", I'll defensively point out that in the history of computing there have been bytes of other lengths than the now-standard 8 bits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • StatzStatz Posts: 28
    edited 2008-11-27 22:31
    Well, here it is. I am typing in the letter a in the and storing it in a variable with the debugin command. I want to work with the letter, but I don't know how. How would I go about doing that.


    like I want to write "If variable = 'a'" or something like that
  • StatzStatz Posts: 28
    edited 2008-11-27 22:33
    Wow, I just answered my own question, I can do (if variable = "a") lol. Thanks guys
  • StatzStatz Posts: 28
    edited 2008-11-27 22:36
    nvm, question still up, didn't work
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-27 23:08
    Should work. Are you comparing variables of the same length? Gotta watch that sometimes, especially when looking for equality.

    Also you should keep in mind that when you're comparing things, upper-case "A" is not the same as lower-case "a".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net

    Post Edited (Carl Hayes) : 11/27/2008 11:14:20 PM GMT
  • JDJD Posts: 570
    edited 2008-11-29 00:08
    Statz,

    If I understand correctly, you want to use a IF...THEN command for a variable. correct?

    If so, it should look something like the following:

    IF variable = "a" THEN
    some set of commands, or assignments
    ENDIF

    Good examples of how to use this command can be found in our educational text What's A Microcontroller and also the BASIC Stamp Syntax & Reference Manual; both of which can be downloaded for free

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com
Sign In or Register to comment.