Beginner question in boolean algebra

67 Views Asked by At

I am studying some of the bit-manipulation techniques for binary numbers and writing programs for them in assembly language, for example

# Isolate the rightmost 0-bit.
y = ~x & (x+1)

# Right propagate the rightmost 1-bit.
y = x | (x-1)

I would like to understand why some of these work from an algebraic perspective, and I'm not quite sure where to look to understand the basic properties of boolean algebra. I've taken alook at purchasing a book such as Introduction to Boolean Algebras, but this is about 500 pages, and probably way too much for what I'm looking for. I'm more interested in the basic properties such as what's distributive, associative, simplifying expressions, seeing how results 'look', etc.

Where can I learn about the various properties of the boolean operators as it applies to a basic programming understanding? Is it included in a discrete mathematics course, or is it its own field? Additionally, how would the above two equations work/simplify to?

1

There are 1 best solutions below

2
On

You can work out by taking some examples

take x=110 (6)

~x=001

(x+1)=111 (7)

y = ~x & (x+1) = 001 & 111

y=001

In this way you got that first bit is the rightmost 0.

Similarly you can try for the second one also.

You can refer this and this if you want to learn about boolean algebra in relation to programming. They have quick explanation of basic boolean algebra and it will help you get started.