[Kaffe] Help!, problems with ZipOutputStream.
Moses DeJong
dejong at cs.umn.edu
Wed Feb 17 15:53:08 PST 1999
On Wed, 17 Feb 1999, Archie Cobbs wrote:
> Moses DeJong writes:
> > I have been looking at the src for the java.util.zip
> > classes and I am a little confused about this whole
> > signed vs unsigned thing. The code in ZipOutputStream
> > and ZipInputStream uses >> operations on long values
> > that have been cast to int values. First off, would
> > casting a long to an int keep the sign bit from the
> > long? If such a cast does keep the sign bit from the
You are correct. I did some more testing and it looks like
casting from long to int does indeed throw out the sign bit.
I am still not sure about using >> instead of >>> but I will
have to do more testing to find out.
> Casting long to int in C simply truncates the top bits,
> which does not necessarily preserve the sign bit.
>
> In C, "(a) >> (b)" is implementation defined unless
> (a) is unsigned, in which case the shift does not
> preserve the sign bit.
>
> > So I think a "fix" for the bit shifting and casting
> > problems is to use >>> and bitwise AND operators
> > to get the unsigned values out of the longs that
> > they are stored in. Does anyone agree or disagree?
>
> If x is a long, "(int)x" should do this OK.
>
> Not sure if this answers your question or not..
>
> -Archie
>
> ___________________________________________________________________________
> Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com
>
More information about the kaffe
mailing list