[OT] help w/ bitwise comparison operators

Erik Price eprice at ptc.com
Thu Mar 20 15:58:03 EST 2003


Yeah, this is totally offtopic of Linux but I know there are some 
helpful hackers on this list and was wondering if anyone wouldn't mind 
letting me know if there is a mental trick to working out the results of 
bitwise comparison operators.

Do you really have to convert the number to binary and then do a 
digit-for-digit comparison?  When I was in grade school we learned how 
to multiply two longer numbers together using an age-old but still 
really cool shortcut where you just do single-digit multiplication 
against the second number and carry the one, or carry the four, or 
whatever.  (Hope I'm making myself clear with this.)  The book I'm 
studying explains that an easy way to do a left bitwise shift is to 
multiply the left operand by 2 ^ N where N is the number you want to 
shift by, and that you can do the same with a right bitwise shift except 
using division instead.  Is there something similar for the bitwise 
comparisons for situations like:

7 & 3

or

6 | 13

?



Thanks,

Erik





More information about the gnhlug-discuss mailing list