OT: Wacky Way To Read A Byte[] - someone help explain?

Hans Fugal hans at fugal.net
Fri May 19 21:08:06 MDT 2006


On Fri, 19 May 2006 at 17:13 -0600, Michael L Torrie wrote:
> On Fri, 2006-05-19 at 15:21 -0600, Stephen Ward wrote:
> > >> I haven't looked at the spec to see what exactly
> > >> causes the bytes to get promoted to ints, but they
> > >> do.  It's probably the fact that a literal number is
> > >> interpreted as an int, not a byte, so byteval << intval
> > >> causes the byte to be promoted to an int.
> > 
> > Actually, I believe the << operator promotes each of its operands to ints.
> 
> Is this not a bad thing?  I definitely wouldn't want a number I'm
> shifting to be casted to an int as that can change the meaning of the
> shift.  
> 
> But Java doesn't have unsigned numbers, right?
> 
> I'll add that to my list of reasons to dislike Java.

Well that's what C does.


    int main(void)
    {
        printf("%x %x\n",
               ((unsigned char)0xff) << 8,
               ((char)0xff) << 8);
    }

produces

    ff00 ffffff00

Neither of which is a char, unsigned or no.

-- 
Hans Fugal ; http://hans.fugal.net
 
There's nothing remarkable about it. All one has to do is hit the 
right keys at the right time and the instrument plays itself.
    -- Johann Sebastian Bach
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : http://plug.org/pipermail/plug/attachments/20060519/d41a6de0/attachment-0001.pgp


More information about the PLUG mailing list