The problem with answering your question correctly is that you haven't defined what "A" and "B" are in your examples.
By this sentence, I am trying to say that the information of B is embedded in A.
Sheet music encodes some musical events, and a string of bytes (together with a certain character table, e.g. ASCII) encodes some text, but if you enclose a letter in a biography, this biography doesn't "encode" the letter.
One of the prerequisites of encoding is that a certain translation process takes place: in case of text encoding, this could be the ASCII table, which translates (8-bit) numbers to characters and vice versa. In case of a ROT13, cipher "A" encodes "N", "B" encodes "O", and so on.
The relationship between encoded data and encoding data doesn't need to be 1:1 either. Compression algorithms (both lossless and lossy, like TIFF, ones) are also a form of encoding.
---- EDIT: -----
Given the further context you provided in your edit: yes, you could use "encode" in this case, because the mentioned "translation" - that is, doing something by means of doing something else - is in fact taking place: you operate a gate and, by doing that, calculate a mathematical function.