Shop OBEX P1 Docs P2 Docs Learn Events
Why can we assign the literals to numbers but not to variables (Answer: use nu — Parallax Forums

Why can we assign the literals to numbers but not to variables (Answer: use nu

bassmasterbassmaster Posts: 181
edited 2007-02-12 00:55 in Propeller 1
Why can we assign the literals to numbers but not to variables ?


·· ($mybyte )
· ($41)






Post Edited (bassmaster) : 2/12/2007 12:58:03 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-11 23:22
    You don't need to cast anything. All values are integers and all method parameters and result are 32-bit integers. Just put "tv.out(mybyte)".
  • codekingcodeking Posts: 39
    edited 2007-02-11 23:23
    bassmaster said...
    tv.out($mybyte )

    The prop tool thinks that $mybyte is a hex number, not a var. Since M,Y,B, and T aren't used in hex, it's giving you that error. tv.hex(mybyte) will print (Whatever the hex of A is) on the screen. I think what your think is that tv.hex changes mybyte into a hex. Hex, binary, numbers, and ASCII are all the same, just visualized in a different form. mybyte := "A", mybyte := $(hex of A), mybyte := (Number of A), and mybyte := %(binary of A) are all the same. Just like : - ) smile.gif and : smile : smile.gif are the same.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • KaioKaio Posts: 253
    edited 2007-02-11 23:23
    Use tv.out(mybyte) as in the instruction before.

    Use $ only to specify hex values like in tv.out($41).
  • KaioKaio Posts: 253
    edited 2007-02-11 23:45
    $ is not an operator, it's only an indicator used on constants to specify the used value format.

    $ for hex values
    % for binary values

    If none indicator is given it's a decimal value.

    Please have a look at page 158 in propeller manual.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-11 23:46
    The problem is that you're thinking of "$" and "%" as operators and they're not. They're part of the syntax of numbers. A "$" introduces a hex literal and a "%" introduces a binary literal. The compiler also accepts "%%" to introduce a literal in base 4 (nibble literal?). This is much like the use of a double quote to introduce a string or character constant. The error message is correct.
  • bassmasterbassmaster Posts: 181
    edited 2007-02-12 00:03
    Ok You are right, my bad, still not understading why I can do this with a number but not a variable byte. see page 312:

    Hexadecimal indicator: used to indicate a value is being expressed in hexadecimal
    (base-16).

    Why can "value" not be the value of a variable byte

    Post Edited (bassmaster) : 2/12/2007 12:07:34 AM GMT
  • bassmasterbassmaster Posts: 181
    edited 2007-02-12 00:19
    Fixed: FYI ( Just expected the compiler to do this for me or have hex dec bin built in like in pbasic)

    hex(mybyte)


    PUB hex(value)
    i = 0

    value <<= (8) << 2
    repeat 3
    ·outbyte(i) := (lookupz((value <-= 4) & $F : "0".."9", "A".."F"))
    ·i := i +1

    Post Edited (bassmaster) : 2/12/2007 12:45:52 AM GMT
  • KaioKaio Posts: 253
    edited 2007-02-12 00:26
    Mike Green said...

    All values are integers and all method parameters and result are 32-bit integers.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-12 00:41
    bassmaster,
    Yeah. The operators and statements are so useful and varied that it's easy to forget that Spin is really a fairly low level language, much more like Small C than anything else. It doesn't really have floats, doesn't have structures, no macros. When you compare it to the instruction set, it's pretty much 1:1 for expressions, looser for control statements.
    Mike
  • bassmasterbassmaster Posts: 181
    edited 2007-02-12 00:48
    yep, this is not hard to roll my own, or in this case modify existing hex from tv_text
  • bassmasterbassmaster Posts: 181
    edited 2007-02-12 00:55
    just found all I needed in numbers.spin!!!!!!!!!!!!!!

    PUB ToStr(Num, Format): StrAddr
    {{Convert long Num to z-string using Format; returns string address.
    PARAMETERS: Num = 32-bit signed value to translate to ASCII string.
    Format = Indicates output format: base, size, grouping, etc. See "FORMAT SYNTAX" for more information.
    RETURNS: Actual length of output string, not including null terminator.}}
    BCXToText(Format >> 19 & 7, Format >> 13 & $3F, Format >> 12 & 1, Format >> 11 & 1, Format >> 5 & $3F, BinToBCX(Num, Format & $1F #> 2 <# 16))
    StrAddr := @StrBuf
Sign In or Register to comment.