HELP!!! fast
Archiver
Posts: 46,084
does any body know how to grab a single digit out of a (shiftin)
string.
debug window
_________________________________________________
11111111 11111111 255 255 255 255
- --
_________________________________________________
(nuts and volts "bs2 meets ps2"
playstation controller controlled robot source code)
please reply before (3/10/04)
string.
debug window
_________________________________________________
11111111 11111111 255 255 255 255
- --
_________________________________________________
(nuts and volts "bs2 meets ps2"
playstation controller controlled robot source code)
please reply before (3/10/04)
Comments
On the BS2, BS2e, BS2sx and BS2p, an alias can also serve as a window into
a portion of another variable. This is done using "modifiers." Here the
alias is assigned with a modifier that specifies what part:
Rhino VAR WORD ' A 16-bit variable.
Head VAR Rhino.HIGHBYTE ' Highest 8 bits of Rhino.
Tail VAR Rhino.LOWBYTE ' Lowest 8 bits of Rhino.
Given that example, if you write the value %1011000011111101 to Rhino,
then Head would contain %10110000 and Tail would contain %11111101.
Table 4.3 lists all the variable modifiers. PBASIC2 lets you apply these
modifiers to any variable name and to combine them in any fashion that
makes sense. For example, it will allow:
Rhino VAR WORD ' A 16-bit variable.
Eye VAR Rhino.HIGHBYTE.LOWNIB.BIT1 ' A bit.
The commonsense rule for combining modifiers is that they must get
progressively smaller from left to right. It would make no sense to specify,
for instance, the low byte of a nibble, because a nibble is smaller than a
byte! And just because you can stack up modifiers doesn
slightly more verbose variable definition that will let you alias bits
easily.
Instead of this:
buffer VAR Byte(6)
...do this:
buffer VAR Byte
buffer1 VAR Byte
buffer2 VAR Byte
buffer3 VAR Byte
buffer4 VAR Byte
buffer5 VAR Byte
Even with the second definition set you can access elements of the array
as buffer(idx). Just make sure you keep the definitions in order, since
the compiler arranges RAM byte type and then in the order they're
defined.
And finally ... please don't copy large sections of the help file to
your posts -- it just chews up a lot of space in subscriber mail boxes.
-- Jon Williams
-- Parallax
Original Message
From: smartdim@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=2KroeYKUxKE8W9--T28xS6Kgwb3K41f8G-41dgsB9q4k6XKa2vKi0XTBxKIsxOe9s-yjWYMlnzRLvw]smartdim@a...[/url
Sent: Tuesday, March 09, 2004 5:22 PM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] HELP!!! fast
FROM TH E MANUAL
On the BS2, BS2e, BS2sx and BS2p, an alias can also serve as a window
into a portion of another variable. This is done using "modifiers." Here
the alias is assigned with a modifier that specifies what part: Rhino
VAR WORD ' A 16-bit variable. Head VAR Rhino.HIGHBYTE ' Highest 8 bits
of Rhino. Tail VAR Rhino.LOWBYTE ' Lowest 8 bits of Rhino. Given that
example, if you write the value %1011000011111101 to Rhino, then Head
would contain %10110000 and Tail would contain %11111101.
Table 4.3 lists all the variable modifiers. PBASIC2 lets you apply these
modifiers to any variable name and to combine them in any fashion that
makes sense. For example, it will allow: Rhino VAR WORD ' A 16-bit
variable. Eye VAR Rhino.HIGHBYTE.LOWNIB.BIT1 ' A bit.
The commonsense rule for combining modifiers is that they must get
progressively smaller from left to right. It would make no sense to
specify, for instance, the low byte of a nibble, because a nibble is
smaller than a byte! And just because you can stack up modifiers doesn't
mean that you should unless it is the clearest way to express the
location of the part you want get at. The example above might be
improved: Rhino VAR WORD ' A 16-bit variable. Eye VAR Rhino.BIT9 ' A
bit. Although we've only discussed variable modifiers in terms of
creating alias variables, you can also use them within program
instructions: Rhino VAR WORD ' A 16-bit variable. Head VAR
Rhino.HIGHBYTE ' Highest 8 bits of rhino. Rhino = 13567 DEBUG ? Head '
Show the value of alias variable Head. DEBUG ? Rhino.HIGHBYTE '
Rhino.HIGHBYTE works too. STOP Modifiers also work with arrays. For
example: MyBytes VAR BYTE(10) ' Define 10-byte array.
MyBytes(0) = $AB ' Hex $AB into 0th byte
DEBUG HEX ? MyBytes.LOWNIB(0) ' Show low nib ($B)
DEBUG HEX ? MyBytes.LOWNIB(1) ' Show high nib ($A)
Table 4.3: BS2, BS2e, BS2sx and
BS2p Variable Modifiers.
4: BASIC Stamp Architecture - Aliases and Modifiers
BASIC Stamp Programming Manual 2.0c * www.parallaxinc.com * Page 55 If
you looked closely at that example, you probably thought it was a
misprint. Shouldn't MyBytes.LOWNIB(1) give you the low nibble of byte 1
of the array rather than the high nibble of byte 0? Well, it doesn't.
The modifier changes the meaning of the index value to match its own
size. In the example above, when MyBytes() is addressed as a byte array,
it has 10 byte-sized cells numbered 0 through 9. When it is addressed as
a nibble array, using MyBytes.LOWNIB(), it has 20 nibble-sized cells
numbered 0 through 19. You could also address it as individual bits
using MyBytes.LOWBIT(), in which case it would have 80 bit-sized cells
numbered 0 through 79. What if you use something other than a "low"
modifier, say MyBytes.HIGHNIB()? That will work, but its effect will be
to start the nibble array with the high nibble of MyBytes(0). The
nibbles you address with this nib array will all be contiguous, one
right after the other, as in
the
previous example.
MyBytes VAR BYTE(10) ' Define 10-byte array.
MyBytes(0) = $AB ' Hex $AB into 0th byte
MyBytes(1) = $CD ' Hex $CD into next byte
DEBUG HEX ? MyBytes.highnib(0) ' Show high nib of cell 0 ($A) DEBUG HEX
? MyBytes.highnib(1) ' Show next nib ($D) This property of modified
arrays makes the names a little confusing. If you prefer, you can use
the less-descriptive versions of the modifier names; BIT0 instead of
LOWBIT, NIB0 instead of LOWNIB, and BYTE0 instead of LOWBYTE. These have
exactly the same effect, but may be less likely to be misconstrued. You
may also use modifiers with the 0th cell of an array by referring to
just the array name without the index value in parentheses. It's fair
game for aliases and modifiers, both in VAR directives and in
instructions.
does any body know how to grab a single digit out of a (shiftin)
string.
debug window
_________________________________________________
11111111 11111111 255 255 255 255
- --
[noparse][[/noparse]Non-text portions of this message have been removed]
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....