You want to invert the transformation that got you output from input but unfortunately the logic is flawed. | is not an inverse of & and * 8 is absolutely not inverse to another * 8. Also, if you want to reverse the action of y = 0x190 - x, it's not a + but rather another x = 0x190 - y (try it on paper!) Finally, if you had all the operations all right, the order of the operations would need to be reversed in order to undo them (first in, last out).
In fact, your transformation can not be inverted, because it loses part of the information that defines input. (Mathematically speaking, it is not injective.) Consider:
uint8_t input = 10;
uint8_t output = ((0x190 - (input * 8)) & 0xFF); /* 0x40 */
uint8_t input2 = 42;
uint8_t output2 = ((0x190 - (input2 * 8)) & 0xFF); /* also 0x40! */
If you had a function that would undo the operation, what would it be expected to return for an output of 0x40, 10 or 42? This has no solution. If you want the original input you'll need to keep a copy of that variable somewhere.
Examples of operations that can be undone in unsigned 8-bit calculations are
- addition and subtraction OF a constant:
y = x + a ⇔ x = y - a,
- subtraction FROM a constant:
y = c - x ⇔ x = c - y, including plain negation (c = 0),
- XOR:
y = x ^ p ⇔ x = y ^ p, including ~x (that's x ^ 0xFF),
- multiplication by a constant in some cases (by odd numbers), but the inverse is not obvious.
An inverse operation to a compound like y = -((x + 0x17) ^ 0x15) would look like x = ((-y) ^ 0x15) - 0x17, notice the reverse order in which the steps are undone.
On the other hand, these are not invertible:
- AND,
- OR,
- multiplication by an even number,
- bit shifts,
- etc.
Sometimes you can find an inverse if that's workable for you. Here, if you are guaranteed that input is between 0 and 18 (that is 0x90 / 8), you can try
uint8_t input = 10;
uint8_t output = 0x90 - (input * 8); // spot two differences
uint8_t newInput = (0x90 - output) / 8;
But if input is larger, for example 20, it will instead give some other value that happens to produce the same output.