[Kaffe] Help!, problems with ZipOutputStream.

Archie Cobbs archie at whistle.com
Wed Feb 17 09:30:17 PST 1999


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

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