05-09-2022, 01:39 AM
(05-02-2022, 12:35 AM)SMcNeill Wrote: One way to break down the logic of IMP is to remember with A IMP B:Then I don't get it! If ANY combinations will give 255, what's the point of it, and how could it be used (if I wanted to)? Can you show a (simple) example?
Your result is *always* going to have all the bits of B set…
For example, let’s assume A and B are both _UNSIGNED _BYTEs.
Now if B =3, the result of A IMP B will be = ??????11, depending on A to fill in the ?
And if B = 5, the result of A IMP B will be = ?????1?1, depending on A to fill in the ?
*Whatever* the final result is, it’s going to have every bit set that B already has set.
And, with that half of the process solved, it’s *also* going to set any bits that A *DOES NOT* have set.
A = 2. B = 3.
In binary, those are:
A = 00000010
B = 00000011
A IMP B is solved by first setting all the bits in the answer to match B: ??????11
Then we toggle all the bits in A: 11111101.
And we set the ones that are on, for our answer: 11111111
2 IMP 3 = 255
(NOT A) OR B
That’s the breakdown of what IMP is doing.
(NOT A) says the result is going to have all the bits set that A does NOT have.
OR B says our result is *also* going to have all the bits set that B does.
A IMP B = (NOT A) OR B
Really, that’s all there is to it. It’s convoluted, and not really something I think most folks ever really need, but that’s all the does in a nutshell.