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?
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/