There's a word, that I can't remember, that means or rather describes a word
or phrase, that by saying it, you do it.
It sounds to me like you're thinking of some term from speech act
theory, possibly "performative". See J. L. Austin, _How to Do Things
With Words_.
Several people have already posted solutions, of course, with various
explanations. Some, such as Dan, tried to provide solutions which
followed Henry's requirements in order, which I imagine was probably
quite useful. I'd like to suggest another way of explaining the "not-A
and B" version, though:
Note that if you read the requirements in the other order, the result
is the same as B, except that some of the bits are reset according to
what's in A. So the first step is easy: copy B into R:
R = B;
Now, you want to reset some of the bits in R, based on A. AND is the
usual operator to clear some bits and leave others unchanged. In
this case, though, you don't want to AND with A, because AND clears
the bits that are 0 in the second operand (or in the first one, but
we're treating the first as "source" and the second as "mask", for
the sake of clarity). You want the opposite - clear bits where A is
1.
So, what you want is an AND that clears where the mask is 1, or you
want a mask that has 1 where A is 0 and vice versa. The latter is
easier - it's just NOT A. So step 2 is to AND R with NOT A:
R = R & ~A;
And, of course, the two steps can be combined into one:
R = B & ~A;
There are lots of ways to arrive at Boolean functions: breaking down
the requirements into steps, writing out the truth table and figuring
out what operators it corresponds to, analysis methods like Karnaugh
maps, and so forth. Sometimes trying a couple of different approaches
will clarify the problem for you.