I have a number (hex) and I want the one's complement of it. For example if X = 20
I want bash to perform a negation and return Y = ~X = DF
. It doesn't have to be in bash, but it should use a common command line tool that I can wrap into a script. Also note that the numbers should all be unsigned and I'd prefer they don't overflow the bits available (e.g., 20
would only be 8 bits, so the output should be the 8-bit one's complement of that).
I've tried various things using bash and bc, but haven't found the right combo. Any ideas?
(If anyone cares, the goal is to set the IRQ affinity to a specific CPU and then set the other IRQs to all other processors.)