Shop OBEX P1 Docs P2 Docs Learn Events
Does the DATA comand accept entries in Hexadecimal? — Parallax Forums

Does the DATA comand accept entries in Hexadecimal?

LoopyBytelooseLoopyByteloose Posts: 12,537
edited 2006-08-25 20:30 in BASIC Stamp
I am debuging a program and·have read the DATA section of the manual.

Since it does not explicitly state that entiries may be in hexadecimal [noparse][[/noparse]each data item·has a $ at the beginning], I am beginning to wonder if this may be the source of my problems.

If needed, I·can convert all to decimal format, but Hex is visually easier to manage and identify.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you want more fiber, eat the package.· Not enough?· Eat the manual."········
···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-23 11:28
    George -

    Let me start this with a couple of caveats:

    If a particular PBASIC instruction or command specifies that the parameter MUST be in a particular numeric format (decimal, hex, or binary) any properly designated number representation should be fine.

    All of what I say is subject to any insight that Jeff Martin (PBASIC IDE guru) might offer.

    The IDE has no pre-disposed knowledge of any number format, except as noted above. Thus, it accepts numeric representations with no designator as decimal (default).

    If the programmer adds a $ as a prefix, then this changes for the constant which follows. So too, if the programmer adds a % prefix, then the IDE automatically presumes a binary number. In each of these cases once the IDE is "primed" it will check that the character string presented falls within the scope of the number system expressed.

    In other words, if decimal is presumed only the numeric characters 0-9 are permitted within the numeric character scan. If binary is specified, then only 0 or 1 is permitted within the numeric character scan. If hexadecimal is specified, then 0-9 and A-F (also a-f) are permitted. Programatically, within the IDE, this is easier than one might think.

    I hope that gives you some insight.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-08-23 15:39
    Thanks Bruce,
    As I understand you, when the Manual's text mentions a range in decimal [noparse][[/noparse]such as 0-256], the IDE will accept the $prefixed in hex or the %prefixed value in binary. After all, everything must eventually be converted by the IDE and written to the EEPROM in binary.

    I do understand that it is very difficult to write a document that really helps begineers which doesn't find itself full of repetition of fundamental rules--some things must be implied. The DATA command section merely discusses decimal and Ascii formats, but there are many situations that entering a big list of DATA, it is easier to read and verify hex or binary entires.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-23 17:23
    George -

    I can't argue with what you said except for the following. You said:

    "As I understand you, when the Manual's text mentions a range in decimal [noparse][[/noparse]such as 0-256], the IDE will accept the $prefixed in hex or the %prefixed value in binary. After all, everything must eventually be converted by the IDE and written to the EEPROM in binary."

    Specifically, this part:

    "a range in decimal [noparse][[/noparse]such as 0-256], the IDE will accept the $prefixed in hex or the %prefixed value in binary"

    I MUST add, "unless it specifies that a given constant be specified in a given format (decimal, hex, binary). I just can't make as broad a statement as you have, since I can envision conditions where a given format MAY be needed. I'm NOT saying that is TRUE, just that it could or MIGHT be true. If you want to give Jeff a "head-scratcher" this may be it, since I DO have a circumstance in mind smile.gif

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-08-23 18:12
    George,

    The DATA can be in any of the Stamp numeric formats. If you want words, be sure to include that with every entry:

    DATA 'abcde', $13,$10,0
    DATA %10001000,%10000100,%010
    DATA WORD 4475, WORD 7544, WORD 0, WORD $4577, WORD %1100011100010

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • El PaisaEl Paisa Posts: 375
    edited 2006-08-24 02:42
    My own experience with Data statements is that the program only reads ONE character at the time.
    The format you want have to be defined after you read the character.
    I am right or wrong?
  • El PaisaEl Paisa Posts: 375
    edited 2006-08-24 02:43
    My previous post refers only to the propeller.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-24 14:31
    Regardless of how any DATA is specified when it's stored it can ultimately be in only one format within the memory, Binary.· So, if you write the DATA in Binary, it is possible to read it back the Decimal value.· Remember, regardless of how it's specified it's just a bunch of 0's and 1's in memory.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-08-25 20:00
    Thanks,
    I just have been thinking too hard.

    As usual, the problem and the preception of the problem are two different things.
    I seem to have my SO and SI wires reversed. That is why my data was being rejected and why my verify was all zeros!

    This feature really helps me program.
    I use binary for DATA like blinking lights or stepper motor sequences as it helps me visualize.
    I use hex for DATA that are forms of address, operational or machine code.
    And I use the DATA in quotes for literal ASCII.
    About the only thing I might use decimal for is plain old numbers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-25 20:30
    I tend to use whatever fits an application...If the datasheet for a device lists all the commands in Hex then I will define them (constants) in Hex and use them that way.· On the other hand my ASCII chart is in both Decimal and Hex, but I tend to remember the Decimal values easier so I use them when specifying direct ASCII values.· I use Binary for patterns and field bit-masks.· You have to go with what works for you.· =)· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.