Shop OBEX P1 Docs P2 Docs Learn Events
highbyte, lowbyte — Parallax Forums

highbyte, lowbyte

ArchiverArchiver Posts: 46,084
edited 2003-09-16 04:32 in General Discussion
Hi All,

As ususal, I am missing a simple fundemental truth. I though that:

bla VAR word
bla = 6500

debug DEC bla.highbyte, DEC bla.lowbyte

would display "6500", however, I get "10025". Do I have to use the DIG
command to do what I want here?

Sorry for the simple question.

Jonathan

www.madlabs.info

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-09-15 15:39
    Hi Jonathan,

    The problem is that 6500 is not 65*256+0, but rather 1964 hex which is
    $19*256+$64 (or 25 and 100). The lowbyte stores the 25 part, which seems
    odd but is not unusual.

    Why not just say DEBUG dec bla

    This will do what you want automatically. There is no easy way to look
    at two bytes independently and figure the decimal digits. You have to
    look at it as a whole (as opposed to hex, octal, or binary digits).

    If you really wanted to pick apart digits, DIG will do it, but only if
    you look at the entire 16-bit word.

    Al Williams
    AWC
    * New servo control kit and more: http://www.al-williams.com/kits.htm

    >
    Original Message
    > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=5YpsmYMNMRXpOvG3x8jE7dgUudSm1a6x6PopkQ4uA_yO5BDl7jXv6klBHKz8KXTMz_tC0CeYfiskG6hd]jpeakall@m...[/url
    > Sent: Monday, September 15, 2003 9:28 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] highbyte, lowbyte
    >
    >
    > Hi All,
    >
    > As ususal, I am missing a simple fundemental truth. I though that:
    >
    > bla VAR word
    > bla = 6500
    >
    > debug DEC bla.highbyte, DEC bla.lowbyte
    >
    > would display "6500", however, I get "10025". Do I have to
    > use the DIG command to do what I want here?
    >
    > Sorry for the simple question.
    >
    > Jonathan
    >
    > www.madlabs.info
    >
    >
    >
    > 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 2003-09-15 15:50
    Al,

    I want to send a word size VAR using serout commands to a PIC co-proccesor
    in a project I am working on. Using the Stamp, the user selects a value for
    the PIC co-processor to use in it's program. What is the easiest way to do
    this?

    Jonathan

    www.madlabs.info


    Original Message
    From: "Al Williams" <alw@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, September 15, 2003 7:39 AM
    Subject: RE: [noparse][[/noparse]basicstamps] highbyte, lowbyte


    > Hi Jonathan,
    >
    > The problem is that 6500 is not 65*256+0, but rather 1964 hex which is
    > $19*256+$64 (or 25 and 100). The lowbyte stores the 25 part, which seems
    > odd but is not unusual.
    >
    > Why not just say DEBUG dec bla
    >
    > This will do what you want automatically. There is no easy way to look
    > at two bytes independently and figure the decimal digits. You have to
    > look at it as a whole (as opposed to hex, octal, or binary digits).
    >
    > If you really wanted to pick apart digits, DIG will do it, but only if
    > you look at the entire 16-bit word.
    >
    > Al Williams
    > AWC
    > * New servo control kit and more: http://www.al-williams.com/kits.htm
    >
    > >
    Original Message
    > > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=CC3XzLp1SsuDXgXbkOHoWoO4jZwj7dCEoFsatRqb9E-rwSsBWzsTXU10LXHx4UCfyEBgUkzXOvEh4LICKkQ]jpeakall@m...[/url
    > > Sent: Monday, September 15, 2003 9:28 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] highbyte, lowbyte
    > >
    > >
    > > Hi All,
    > >
    > > As ususal, I am missing a simple fundemental truth. I though that:
    > >
    > > bla VAR word
    > > bla = 6500
    > >
    > > debug DEC bla.highbyte, DEC bla.lowbyte
    > >
    > > would display "6500", however, I get "10025". Do I have to
    > > use the DIG command to do what I want here?
    > >
    > > Sorry for the simple question.
    > >
    > > Jonathan
    > >
    > > www.madlabs.info
    > >
    > >
    > >
    > > 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/
    > >
    > >
    > >
    > >
    >
    >
    > 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 2003-09-15 22:57
    Hi Jonathan

    You can send the two bytes to the PIC most efficiently and simply...

    debug bla.highbyte,bla.lowbyte

    and program the PIC to receive those two bytes in order to
    reconstruct the word value.

    Alternatively, the Stamp could send 4 hex bytes
    debug hex4 bla

    and the PIC would have to be programmed to receive 4 bytes and to
    reconstruct the original word out of the low nibble of each. Simple
    job for the PIC.

    Finally, the Stamp could send decimal:
    debug dec5 bla
    and the PIC would have to receive 5 decimal digits, subtract 48 from
    each one (so that ascii "0" to "9" become binary 0 to 9) and multiply
    each digit times its appropriate power of 10 (10000, 1000, 100, 10,
    1) and add them up to reconstruct the original. A lot more work for
    the PIC!!

    --- Tracy
    http:/www.emesystems.com






    >As ususal, I am missing a simple fundemental truth. I though that:
    >
    >bla VAR word
    >bla = 6500
    >
    >debug DEC bla.highbyte, DEC bla.lowbyte
    >
    >would display "6500", however, I get "10025". Do I have to use the DIG
    >command to do what I want here?

    >>I want to send a word size VAR using serout commands to a PIC co-proccesor
    >>in a project I am working on. Using the Stamp, the user selects a value for
    >>the PIC co-processor to use in it's program. What is the easiest way to do
    >>this?
    >>
    >>Jonathan
    >>
    >>www.madlabs.info
    >>
    >>
    >>
    Original Message
    >>From: "Al Williams" <alw@a...>
    >>To: <basicstamps@yahoogroups.com>
    >>Sent: Monday, September 15, 2003 7:39 AM
    >>Subject: RE: [noparse][[/noparse]basicstamps] highbyte, lowbyte
    >>
    >>
    >> > Hi Jonathan,
    >> >
    >> > The problem is that 6500 is not 65*256+0, but rather 1964 hex which is
    >> > $19*256+$64 (or 25 and 100). The lowbyte stores the 25 part, which seems
    >> > odd but is not unusual.
    >> >
    >> > Why not just say DEBUG dec bla
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-16 02:30
    You're chopping a 16 bit value into two separate 8 bit values. 2 ^ 8 = 256
    so that's the magic value for an 8 bit byte.

    Start with 6500 and divide by 256 = 25.factional so 25 is the value of the
    high byte 8 bits

    Subtract 6500 - (25 * 256) = 100 which leaves 100 so 100 is the value of the
    low byte 8 bits.

    You can get the same result if you divide by sucessive powers of two,
    starting with 2^12 = 4096 and mapping the decimal number directly into the
    binary digits and then splitting the first 8 bits and the last 8 bits..
    http://www.usbyte.com/common/Binary%20number%20conversion.htm provides a
    nice calculator, as does the DEBUG command

    Original Message
    From: "Jonathan Peakall" <jpeakall@m...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, September 15, 2003 7:27 AM
    Subject: [noparse][[/noparse]basicstamps] highbyte, lowbyte


    > Hi All,
    >
    > As ususal, I am missing a simple fundemental truth. I though that:
    >
    > bla VAR word
    > bla = 6500
    >
    > debug DEC bla.highbyte, DEC bla.lowbyte
    >
    > would display "6500", however, I get "10025". Do I have to use the DIG
    > command to do what I want here?
    >
    > Sorry for the simple question.
    >
    > Jonathan
    >
    > www.madlabs.info
    >
    >
    >
    > 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 2003-09-16 04:32
    Marv,

    Thanks!

    Jonathan

    www.madlabs.info

    Original Message
    From: "MarvL" <MarvL@m...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, September 15, 2003 6:30 PM
    Subject: Re: [noparse][[/noparse]basicstamps] highbyte, lowbyte


    > You're chopping a 16 bit value into two separate 8 bit values. 2 ^ 8 = 256
    > so that's the magic value for an 8 bit byte.
    >
    > Start with 6500 and divide by 256 = 25.factional so 25 is the value of
    the
    > high byte 8 bits
    >
    > Subtract 6500 - (25 * 256) = 100 which leaves 100 so 100 is the value of
    the
    > low byte 8 bits.
    >
    > You can get the same result if you divide by sucessive powers of two,
    > starting with 2^12 = 4096 and mapping the decimal number directly into
    the
    > binary digits and then splitting the first 8 bits and the last 8 bits..
    > http://www.usbyte.com/common/Binary%20number%20conversion.htm provides a
    > nice calculator, as does the DEBUG command
    >
    >
    Original Message
    > From: "Jonathan Peakall" <jpeakall@m...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Monday, September 15, 2003 7:27 AM
    > Subject: [noparse][[/noparse]basicstamps] highbyte, lowbyte
    >
    >
    > > Hi All,
    > >
    > > As ususal, I am missing a simple fundemental truth. I though that:
    > >
    > > bla VAR word
    > > bla = 6500
    > >
    > > debug DEC bla.highbyte, DEC bla.lowbyte
    > >
    > > would display "6500", however, I get "10025". Do I have to use the DIG
    > > command to do what I want here?
    > >
    > > Sorry for the simple question.
    > >
    > > Jonathan
    > >
    > > www.madlabs.info
    > >
    > >
    > >
    > > 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/
    > >
    > >
    >
    >
    >
    > 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/
    >
    >
    >
Sign In or Register to comment.