[Tutor] bitwise operations

alan.gauld@bt.com alan.gauld@bt.com
Fri, 1 Jun 2001 13:18:42 +0100


> Could anyone tell me all there is to know about bit 
> manipulation; 

No, I doubt it. I don'ty think anyone has figured 
that out yet... Some things you might like to do 
a search on the net for are 'Boolean Algenra' 
and 'Bitmasks'

> why a person would want to be fiddling with bits. 

Bits are a compact way of storing a lot of data which 
is boolean by nature.
For example software used for bulk processing of a 
long list of items might keep a note of which items 
have changed(and hence need reprocessing) by adding 
a boolean value flag to the reords - but that (a) 
changes the records and (b) takes up a byte per 
record. An altrernative solution is to store a block 
of memory with a single bit representing each record, 
then simply switch that bit on if the reord changes.

The bulk processor then scans the bits and processes 
the records with a bit set.

This scheme is what is used in practice for 
synchronising mirrored hard disks in large 
data centres etc... the bits represent the 
raw sectors of the disk and the OS updates 
the bit image after every write.

> bitwise operators are but don't tell me how 
> I would use them, or in what cases such use 
> would be benificial. 

But there are myriad other uses for these, 
usually in a low level systems context and 
often in situations where storage space is 
expensive - like networking protocols etc.

I'll leave explaining how to use "bit masks"
to read/write individual bits within a block 
of storage to someone else... :-)

Alan G.