Thanks a ton. This really helped. It works! Also, I understand why it works
and why what I was doing before didn't work. I also understand why putting
my ints first would help. Everything of known length would start at an even
address then. Just out of curiousity how would this work with doubles? With
longs I know that I just have twice as many bytes to shift but doubles are
confusing. I really don't need an answer to this for my program but I was
just curious as to how you shift bits for that.
>From: Marshall Clow <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>CC: "Salma Saad" <[EMAIL PROTECTED]>
>Subject: Re: problem reading integers
>Date: Tue, 4 Sep 2001 14:32:41 -0700
>
>At 9:14 PM -0700 9/4/01, Salma Saad wrote:
>
> >I wrote:
> >>You have to read the 4 bytes on at a time, and assemble the long
>yourself.
> >>
> >> range->startRange = *s++ & 0x000000FF; range->startRange <<= 8;
> >> range->startRange |= *s++ & 0x000000FF; range->startRange <<= 8;
> >> range->startRange |= *s++ & 0x000000FF; range->startRange <<= 8;
> >> range->startRange |= *s++ & 0x000000FF;
> >>
>
> >Thanks for the help. I am a java programmer with little expereince
>shifting bits and doing things at that low level. I would very much like to
>understand the code before I use it though. I assume that
> >range->startRange = *s++ & 0x000000FF;
> >
> >puts the first byte into range->startRange at the right most position? is
>this right?
>
>That is correct.
>The reason for the '& 0x000000FF' is that in C (on some/many compilers),
>'char' is a signed data type, and 0x84, say, will become 0xFFFFFF84, which
>would mess up the other bytes.
>
> > does doing
> >
> >range->startRange <<= 8;
> >shift it so that I can do
> >
> >range->startRange = *s++ & 0x000000FF; to write the next one in??
>
>Almost.
>You need to do:
> range->startRange |= *s++ & 0x000000FF;
>to 'or' the next byte in.
>
>
> >Am I right in understanding how it works? I do this 4 times, one for each
>byte right?
> >
>
>Right.
>
>--
>-- Marshall
>
>Marshall Clow Idio Software <mailto:[EMAIL PROTECTED]>
>Hey! Who messed with my anti-paranoia shot?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/