Shop OBEX P1 Docs P2 Docs Learn Events
fuzzy math, referencing, and exchanging information — Parallax Forums

fuzzy math, referencing, and exchanging information

ArchiverArchiver Posts: 46,084
edited 2001-11-26 17:30 in General Discussion
Thanks Tracy,
How can I reference bits and nibbles from other indices without
another byte variable? For instance, how can I reference a low nibble
for byte_array(3)?

Another question is what will happen if I do the following:

On the master (BS2SX):
dayh VAR nib
day VAR byte

Main:
SERIN 1\0, 16624, 30, [noparse][[/noparse]dayh, day]
GOTO Main
END

On the slave (BS2):
tdata VAR byte(9)

Main:
SEROUT 5\4, 16468, 30, [noparse][[/noparse]tdata(2), tdata(3)]
GOTO Main
END

What will dayh and day variables receive? Will it be

a.) dayh = tdata(2).highnib, day.highnib = tdata(2).lownib,
day.lownib = tdata(3).highnib
b.) dayh = tdata(2).lownib, day = tdata(3)
c.) dayh = tdata(2).highnib, day = tdata(3)

Can't think of any other multiple choice scenarios. any response will
be appreciated.

Thanks,
RP

--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
> >I was wondering how I can address bits
> >and nibbles from a byte array. I found out that byte_array
> >(index).lownib is a syntax error.
>
>
> byte_array.nib0(index) will reference nibs.
> byte_array.bit0(index) will reference bits
>
> byte_array(0) is the same variable as byte_array
>
> example with alias names:
>
> byte_array var byte(8) ' array of 8 bytes
> bat var byte_array ' alias for the 0th byte
> ' e.g., bat(7) is the last byte of 8
> gnat var bat.nib0 ' alias for 0th nibble
> ' e.g., gnat(15) is the last nib of 16
> bitty var bat.bit0 ' alias for 0th nibble
> ' e.g., bitty(63) for the last bit of 64
>
> -- Tracy

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-24 01:09
    >Thanks Tracy,
    >How can I reference bits and nibbles from other indices without
    >another byte variable? For instance, how can I reference a low nibble
    >for byte_array(3)?

    Hi Ravi,

    I am not sure quite what you want to do, but the easiest way would be
    to play tricks with the index.

    low nib of byte_array(index) is byte_array.nib0(index*2)
    and
    high nib of byte_array(index) is byte_array.nib0(index*2+1).

    For example, when index=3, the corresponding indexes for the low and
    high nibs are 6 and 7. As you have discovered by now, you cannot get
    away with, byte_array(3).nib0, a syntax error. And while
    byte_array.nib0(3) is okay for syntax, is refers to the high nibble
    of the second byte, not to the low nibble of the third byte.

    >
    >Another question is what will happen if I do the following:
    >
    >On the master (BS2SX):
    >dayh VAR nib
    >day VAR byte
    >
    >Main:
    > SERIN 1\0, 16624, 30, [noparse][[/noparse]dayh, day]
    > GOTO Main
    > END
    >
    >On the slave (BS2):
    >tdata VAR byte(9)
    >
    >Main:
    > SEROUT 5\4, 16468, 30, [noparse][[/noparse]tdata(2), tdata(3)]
    > GOTO Main
    > END
    >
    >What will dayh and day variables receive? Will it be
    >
    >a.) dayh = tdata(2).highnib, day.highnib = tdata(2).lownib,
    > day.lownib = tdata(3).highnib
    >b.) dayh = tdata(2).lownib, day = tdata(3)
    >c.) dayh = tdata(2).highnib, day = tdata(3)

    I'm not sure what tdata(n) is. But if it is a byte array, then I
    think the answer is (b). Serout and Serin always justfy each data
    element as a byte.

    BTW, the "30" in the serin and serout will become pacing delays. Is
    that what you want, or do you want timeouts for flow control?

    >
    >Can't think of any other multiple choice scenarios. any response will
    >be appreciated.


    huh? Please explain more are you trying to do.

    >
    >Thanks,
    >RP
    >
    >--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > > >I was wondering how I can address bits
    > > >and nibbles from a byte array. I found out that byte_array
    > > >(index).lownib is a syntax error.
    > >
    > >
    > > byte_array.nib0(index) will reference nibs.
    > > byte_array.bit0(index) will reference bits
    > >
    > > byte_array(0) is the same variable as byte_array
    > >
    > > example with alias names:
    > >
    > > byte_array var byte(8) ' array of 8 bytes
    > > bat var byte_array ' alias for the 0th byte
    > > ' e.g., bat(7) is the last byte of 8
    > > gnat var bat.nib0 ' alias for 0th nibble
    > > ' e.g., gnat(15) is the last nib of 16
    > > bitty var bat.bit0 ' alias for 0th nibble
    > > ' e.g., bitty(63) for the last bit of 64
    > >
    > > -- Tracy
    >
    >
    >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.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-24 01:37
    Hi Tracy,

    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Thanks Tracy,
    > >How can I reference bits and nibbles from other indices without
    > >another byte variable? For instance, how can I reference a low
    nibble
    > >for byte_array(3)?
    >
    > Hi Ravi,
    >
    > I am not sure quite what you want to do, but the easiest way would
    be
    > to play tricks with the index.
    >
    > low nib of byte_array(index) is byte_array.nib0(index*2)
    > and
    > high nib of byte_array(index) is byte_array.nib0(index*2+1).
    >
    > For example, when index=3, the corresponding indexes for the low
    and
    > high nibs are 6 and 7. As you have discovered by now, you cannot
    get
    > away with, byte_array(3).nib0, a syntax error. And while
    > byte_array.nib0(3) is okay for syntax, is refers to the high nibble
    > of the second byte, not to the low nibble of the third byte.

    How would I alias them? So far, I have gotten syntax errors when I
    type, for instance, "jhday VAR tdata.nib0(4)." However, I
    will try to work with what you are saying.

    >
    > >
    > >Another question is what will happen if I do the following:
    > >
    > >On the master (BS2SX):
    > >dayh VAR nib
    > >day VAR byte
    > >
    > >Main:
    > > SERIN 1\0, 16624, 30, [noparse][[/noparse]dayh, day]
    > > GOTO Main
    > > END
    > >
    > >On the slave (BS2):
    > >tdata VAR byte(9)
    > >
    > >Main:
    > > SEROUT 5\4, 16468, 30, [noparse][[/noparse]tdata(2), tdata(3)]
    > > GOTO Main
    > > END
    > >
    > >What will dayh and day variables receive? Will it be
    > >
    > >a.) dayh = tdata(2).highnib, day.highnib = tdata(2).lownib,
    > > day.lownib = tdata(3).highnib
    > >b.) dayh = tdata(2).lownib, day = tdata(3)
    > >c.) dayh = tdata(2).highnib, day = tdata(3)
    >
    > I'm not sure what tdata(n) is. But if it is a byte array, then I
    > think the answer is (b). Serout and Serin always justfy each data
    > element as a byte.
    >
    > BTW, the "30" in the serin and serout will become pacing delays.
    Is
    > that what you want, or do you want timeouts for flow control?

    oops, I wanted timeouts for flow control. Just include "main" after
    30. Sorry about that.

    >
    > >
    > >Can't think of any other multiple choice scenarios. any response
    will
    > >be appreciated.
    >
    >
    > huh? Please explain more are you trying to do.

    I have an 8-byte string which contains the time code. Each bit in the
    bytes is representative of days, times, signal status, etc.

    Thus, I am trying to parse a nibble and/or bits out of a particular
    (appropriate) byte in an array and send them to a different stamp.

    I hope that clears up any confusion.

    Thanks,
    RP

    >
    > >
    > >Thanks,
    > >RP
    > >
    > >--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > > > >I was wondering how I can address bits
    > > > >and nibbles from a byte array. I found out that byte_array
    > > > >(index).lownib is a syntax error.
    > > >
    > > >
    > > > byte_array.nib0(index) will reference nibs.
    > > > byte_array.bit0(index) will reference bits
    > > >
    > > > byte_array(0) is the same variable as byte_array
    > > >
    > > > example with alias names:
    > > >
    > > > byte_array var byte(8) ' array of 8 bytes
    > > > bat var byte_array ' alias for the 0th byte
    > > > ' e.g., bat(7) is the last byte of 8
    > > > gnat var bat.nib0 ' alias for 0th nibble
    > > > ' e.g., gnat(15) is the last nib of 16
    > > > bitty var bat.bit0 ' alias for 0th nibble
    > > > ' e.g., bitty(63) for the last bit of 64
    > > >
    > > > -- Tracy
    > >
    > >
    > >To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@y...
    > >from the same email address that you subscribed. Text in the
    > >Subject and Body of the message will be ignored.
    > >
    > >
    > >Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-24 15:25
    Hi Tracy,
    Do you remember this site:
    http://www.jamesrusso.com/stamp/archive/1998/stamps.9809/msg00660.html

    I am trying to make the BS2 work as a decoder and the BS2SX my
    central MC to interface with other applications. That is why I asked
    questions about how to reference nibbles and bits from other array
    indices.


    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Thanks Tracy,
    > >How can I reference bits and nibbles from other indices without
    > >another byte variable? For instance, how can I reference a low
    nibble
    > >for byte_array(3)?
    >
    > Hi Ravi,
    >
    > I am not sure quite what you want to do, but the easiest way would
    be
    > to play tricks with the index.
    >
    > low nib of byte_array(index) is byte_array.nib0(index*2)
    > and
    > high nib of byte_array(index) is byte_array.nib0(index*2+1).
    >
    > For example, when index=3, the corresponding indexes for the low
    and
    > high nibs are 6 and 7. As you have discovered by now, you cannot
    get
    > away with, byte_array(3).nib0, a syntax error. And while
    > byte_array.nib0(3) is okay for syntax, is refers to the high nibble
    > of the second byte, not to the low nibble of the third byte.
    >
    > >
    > >Another question is what will happen if I do the following:
    > >
    > >On the master (BS2SX):
    > >dayh VAR nib
    > >day VAR byte
    > >
    > >Main:
    > > SERIN 1\0, 16624, 30, [noparse][[/noparse]dayh, day]
    > > GOTO Main
    > > END
    > >
    > >On the slave (BS2):
    > >tdata VAR byte(9)
    > >
    > >Main:
    > > SEROUT 5\4, 16468, 30, [noparse][[/noparse]tdata(2), tdata(3)]
    > > GOTO Main
    > > END
    > >
    > >What will dayh and day variables receive? Will it be
    > >
    > >a.) dayh = tdata(2).highnib, day.highnib = tdata(2).lownib,
    > > day.lownib = tdata(3).highnib
    > >b.) dayh = tdata(2).lownib, day = tdata(3)
    > >c.) dayh = tdata(2).highnib, day = tdata(3)
    >
    > I'm not sure what tdata(n) is. But if it is a byte array, then I
    > think the answer is (b). Serout and Serin always justfy each data
    > element as a byte.
    >
    > BTW, the "30" in the serin and serout will become pacing delays.
    Is
    > that what you want, or do you want timeouts for flow control?
    >
    > >
    > >Can't think of any other multiple choice scenarios. any response
    will
    > >be appreciated.
    >
    >
    > huh? Please explain more are you trying to do.
    >
    > >
    > >Thanks,
    > >RP
    > >
    > >--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > > > >I was wondering how I can address bits
    > > > >and nibbles from a byte array. I found out that byte_array
    > > > >(index).lownib is a syntax error.
    > > >
    > > >
    > > > byte_array.nib0(index) will reference nibs.
    > > > byte_array.bit0(index) will reference bits
    > > >
    > > > byte_array(0) is the same variable as byte_array
    > > >
    > > > example with alias names:
    > > >
    > > > byte_array var byte(8) ' array of 8 bytes
    > > > bat var byte_array ' alias for the 0th byte
    > > > ' e.g., bat(7) is the last byte of 8
    > > > gnat var bat.nib0 ' alias for 0th nibble
    > > > ' e.g., gnat(15) is the last nib of 16
    > > > bitty var bat.bit0 ' alias for 0th nibble
    > > > ' e.g., bitty(63) for the last bit of 64
    > > >
    > > > -- Tracy
    > >
    > >
    > >To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@y...
    > >from the same email address that you subscribed. Text in the
    > >Subject and Body of the message will be ignored.
    > >
    > >
    > >Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-25 21:39
    >So far, I have gotten syntax errors when I
    >type, for instance, "jhday VAR tdata.nib0(4)."

    If you need to refer to variables both with a fixed name and as an
    array, here is the trick I use. First define all the fixed variable
    names in the specific order you want them. You can then use the
    first variable you define with an array index, even though you have
    not explicitly declared it as an array. The array is "implicit".
    This is a tricky "feature" of the way the Stamp allocates memory.
    You can refer to _any_ variable with an array index, and the stamp
    will return values from successive positions in memory, and the size
    of those variables (bit, nib, byte word) is the same as the size of
    the variable referenced. Exammple:

    tdata0 var byte
    tdata1 var byte
    tdata2 var byte
    tdata3 var byte
    tdata4 var byte
    tdata5 var byte
    tdata var tdata0 ' an alias for array addressing
    tnibs var tdata.nib0 ' a nib alias for array addressing
    tnib10 var tdata5.nib0 ' nib aliases for fixed addressing
    tnib11 var tdata5.nib1
    ii var nib

    for ii=0 to 5
    tdata(ii)=ii ' the array is implied, fill it
    next
    tdata5=tdata(2)+tdata3 ' can refer to fixed or array name
    debug dec tdata5, tab, dec tdata(5),cr ' show same thing
    for ii = 0 to 11
    tnibs(ii)=ii ' fill up as 11 nibs
    next
    debug hex tdata5, tab, hex tnib10,tab, hex tnibs(11),cr
    end
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-26 05:34
    Thanks Tracy,
    One question though.
    Do those variables have to be the first ones declared in any program
    or can I declare other variables prior?

    Regards,
    RP


    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >So far, I have gotten syntax errors when I
    > >type, for instance, "jhday VAR tdata.nib0(4)."
    >
    > If you need to refer to variables both with a fixed name and as an
    > array, here is the trick I use. First define all the fixed
    variable
    > names in the specific order you want them. You can then use the
    > first variable you define with an array index, even though you have
    > not explicitly declared it as an array. The array is "implicit".
    > This is a tricky "feature" of the way the Stamp allocates memory.
    > You can refer to _any_ variable with an array index, and the stamp
    > will return values from successive positions in memory, and the
    size
    > of those variables (bit, nib, byte word) is the same as the size of
    > the variable referenced. Exammple:
    >
    > tdata0 var byte
    > tdata1 var byte
    > tdata2 var byte
    > tdata3 var byte
    > tdata4 var byte
    > tdata5 var byte
    > tdata var tdata0 ' an alias for array addressing
    > tnibs var tdata.nib0 ' a nib alias for array addressing
    > tnib10 var tdata5.nib0 ' nib aliases for fixed addressing
    > tnib11 var tdata5.nib1
    > ii var nib
    >
    > for ii=0 to 5
    > tdata(ii)=ii ' the array is implied, fill it
    > next
    > tdata5=tdata(2)+tdata3 ' can refer to fixed or array name
    > debug dec tdata5, tab, dec tdata(5),cr ' show same thing
    > for ii = 0 to 11
    > tnibs(ii)=ii ' fill up as 11 nibs
    > next
    > debug hex tdata5, tab, hex tnib10,tab, hex tnibs(11),cr
    > end
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-26 17:30
    >Thanks Tracy,
    >One question though.
    >Do those variables have to be the first ones declared in any program
    >or can I declare other variables prior?
    >
    >Regards,
    >RP

    You can declare other variables prior. The important thing is to
    declare them in the order that you want them in the array. The Stamp
    compiler allocates memory as follows: first all the word variables
    in the order you declare them, then the bytes, then the nibs and last
    the bits. If you declare a bunch of bytes in a certain order, that
    is how they will end up in the Stamp memory.

    >--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > > If you need to refer to variables both with a fixed name and as an
    > > array, here is the trick I use. First define all the fixed
    >variable
    > > names in the specific order you want them. You can then use the
    > > first variable you define with an array index, even though you have
    > > not explicitly declared it as an array.
Sign In or Register to comment.