Post by Paul CusbishHi there,
Thanks a bunch for your replies - very good stuff.
So basically, i use an AND to highlight certain bits, for say, testing
purposes, etc?
Is there a guide which details what kind of operations the other
bitwise stuff is useful for?
<<, >>, ~, etc??
Thanks again, your help is much appreciated!
Paul.
Hello:
I don't know of any handbook, but I have seen
the bit operations used as:
(nibble is four bits -- half a byte)
(1) Turning bits off (and with 0) and on (and with 1)
but of course the bit is imbedded in a word
of control and status bits;
(2) Testing bits; for example if we have a byte
10111100
and we want to test bit 3 (from the lsb), we
would and with 00001000 (hex 08) and test
for non zero
(3) Digging bits out of a word; for example,
if we have a byte with
10111100
and we want to dig the four middle bits out,
we would and with 00111100 (hex 3C), and
we would probably want to shift it two
places to the right (>> 2).
(4) Inserting a nibble or some such into a word;
for the byte above, if we wished to insert
an arbitary nibble in that middle position
we could do the following:
1011100 and 11000011 -> 10000000 (word)
nibble << 2 -> nibbler
word or nibbler -> word
(5) The DEC PDP-1 had a slow and clumsy multiplier.
I implemented multiply-by-ten as a series of
shifts and adds. In C this would be
((word << 2) + word)<< 1
left shift (<<) by one is a multiplication by two
right shift (>>) by one is a division by two
In this case we are computing ((word*4)+word)*2
john slimick
***@pitt.edu