[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking for Long Tooth...



In case anyone's keeping score, I did mention the use to store booleans as
bits in my original email:

* Old file formats - Like the previous example.  A long time ago, (when
dinosaurs still roamed the earth and when I was in high-school)  people did
not have much disk space.  So file formats made HEAVY use of bit fields to
store a series of boolean flags.  To read or write these flags use need -
bitwise operators.


----- Original Message -----
From: "Henri Yandell" <bayard@generationjava.com>
To: "Christopher Fowler" <cfowler@outpostsentinel.com>
Cc: "Henri Yandell" <bayard@generationjava.com>; "Scott P. Smith"
<ssmith@scott-smith.com>; "Atlanta Java Users Group" <ajug-members@ajug.org>
Sent: Wednesday, April 09, 2003 9:54 AM
Subject: Re: Looking for Long Tooth...


>
> Yeah. This seems to be a major 'plus' to bitwise manipulation. Improved
> performance given a diminishing readability.
>
> For example, rather than using a boolean[], we could be using a BitMask
> class or an int [depending on size of array etc].
>
> The biggest problem here is that for many developers, the only need to
> learn and get used to the bitwise syntax would be to understand the
> performance enhancements. A bit of a catch-22.
>
> As with most optimisation, it fits into the category of doing it after
> you've deduced you have a problem. With lots of nice comments.
>
> Hen
>
> On 9 Apr 2003, Christopher Fowler wrote:
>
> > Another point is that everytime you use a boolean in Java, you could
> > store that same info in 1 bit.
> >
> >
> > On Wed, 2003-04-09 at 09:39, Henri Yandell wrote:
> > >
> > >
> > > On Wed, 9 Apr 2003, Scott P. Smith wrote:
> > >
> > > > I am a little surprised by this question and the other one like it a
few
> > > > weeks ago.  I have a sneaky feeling that I am helping a college
student do
> > > > his homework, but I'll respond anyway.
> > >
> > > I don't find it as surprising. Most of the bitwise manipulation I've
come
> > > into direct contact with has not been very necessary, but just a
result of
> > > old C habits being transferred to the language in question. Irritating
> > > things like:
> > >
> > >  i ^= i;   or somesuch.
> > >
> > > Many Java developers out there have not spent time working in C, and
in
> > > many other languages there's not the need for the low-level bitwise
stuff.
> > >
> > > > There are infinitely many ways these operators can be useful.. But
I'll just
> > > > give a few examples:
> > >
> > > Major ones I've come into contact with are encryption algorithms and
> > > encoding algorithms. At work we encode a series of numbers into one
long
> > > for transmission. I've found BigInteger to have surprising powers here
at
> > > extracting the values. [for when our long got larger than a java long]
> > >
> > > Having a look at the source to an encryption algorithm will see some
very
> > > important uses of bit-shifting.
> > >
> > > > * Data Compression - Many data compression algorithms compress byte
streams
> > > > into bit streams.  To create (and later decode) the bit streams, you
need
> > > > bitwise operators.
> > > >
> > > > * Non-Java Binary File I/O - When working with binary files that
were
> > > > created in C, C++, etc. you will see a lot of use of things like
unsigned
> > > > 16, and 32 bit values. Since Java doesn't support these, you have to
use
> > > > bitwise operators to put the uint16 into a Java int32. And vise
versa.
> > >
> > > Apache's POI project is probably a good example of this. It reads MS
> > > Office formats and as far as I know is full of a need to bit-shift.
Having
> > > a look at their source is probably an education.
> > >
> > > > * Arbitrarily Precision Integer Math - Math packages that implement
64, 128,
> > > > 256 bit integers, etc.  These packages use bitwise operators (at
least I
> > > > think they do).
> > >
> > > BigInteger :)
> > >
> > >
> > > Hen
> >
> >
>
>