Need help solving Boolean Expression

Mar 01, 2009 11 Replies

Hello.. I'm hoping someone could 'steer' me in the right direction as to how and solve the following:



A = B xor (B


Well, you might start from the fact that within A you already know the value of the 2^0 bit of B (since it was xor'd with 0.) Using just four bits to get the point across:

(B3 B2 B1 B0) ^ (B2 B1 B0 0) = (B3^B2 B2^B1 B1^B0 B0)

Do you see a method, now?

Jon

Okay. Perhaps a little walk through it. I can see two obvious approaches.

The first one is like this. Extract B0 from A's A0 position (they are the same value, so just mask it out.) Shift that extracted bit by 1 to the left and xor it with A. Having done that, the value of A1 is now equal to B1. Extract B1 from A's A1 position. Shift that extracted bit by 1 to the left and xor it with A, again. Having done that, the value of A2 is now equal to B2. Etc. Repeat until done.

The second one is hardly any different but perhaps a little faster since you don't have to work one bit at a time all the way across. At least, the looping is less. It goes like this (using 6 bits, for now):

(B5^B4 B4^B3 B3^B2 B2^B1 B1^B0 B0)

Thanks, Jon... Yes, earlier this evening I wrote a C routine much like you have illustrated. Seemed ominous at first, but was much easier once the light came on...

Take care Jim

Thanks, Jon... Yes, earlier this evening I wrote a C routine much like you have illustrated. Seemed ominous at first, but was much easier once the light came on...

Take care Jim

Thanks, Jon... Yes, earlier this evening I wrote a C routine much like you have illustrated. Seemed ominous at first, but was much easier once the light came on...

Take care Jim

It has some resemblance to a crc.

Cheers

Thanks for letting me know you "got it." By the way, that statement above could be written as: v ^= (v

I should add, this looks a lot like gray code generation to me. So I suspect it is related.

Jon

(pseudocode): For B = 1 to N If ((B xor (B

Question for OP, when you do the shift, do you carry the bit shifted out to the other end, or discard it?

here's four ways.

for an n bit number repeat this operation n-1 times

A = A xor (A

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required