Why can we assign the literals to numbers but not to variables (Answer: use nu
bassmaster
Posts: 181
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
·· ($mybyte )
· ($41)
Post Edited (bassmaster) : 2/12/2007 12:58:03 AM GMT
bmp
67K
Comments
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 : - ) and : smile : 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
Use $ only to specify hex values like in tv.out($41).
$ 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.
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
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
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
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