inversion computer science?

hi

How is an inversion computed in computer science? Lets say on an array like its being talked about on wikipedia (http://en.wikipedia.org/wiki/Inversion_(discrete_mathematics)). I found this page difficult to understand since I haven't studied A-level maths, which kind of makes it painfully slow to understand.

If I had an array of the following numbers below as an example, how would I compute an inversion?

3424
654
4334
2324
2324
2424
The link you provided is broken for me but I think I know where you are going.

Inversion is the easiest operation to perform in digital electronics. A NOT gate consists of a pmos transistor and an nmos transistor. You apply the same signal to the gate of both transistors and if your signal is high (1), the pmos transistor closes, connecting your output to ground (0) . If your signal is low (0), the pmos transistor opens and the nmos transistor closes, connecting your output to the power supply (1).

At the software level, we can take a 4-bit number (like 6) which looks like 0110. After we invert it, it looks like 1001. This means that we've inverted each bit. So the inversion of 6 is 9.

Now let's look at your numbers:
3424 in decimal looks like 0xd60 in hex or 1101 0110 0000 in binary. If we invert it, we get 0010 1001 1111 or 0x29f in hex or 671.

Let's now say that 3424 is an unsigned integer (32 bits) so we need to take into account leading zeros. In hex this looks like 0x00000d60, which in binary is 0000 0000 0000 0000 0000 1101 0110 0000. If we invert that, we get 1111 1111 1111 1111 1111 0010 1001 1111 which is 0xfffff29f in hex or 4294963871 in decimal.

In C or C++, to get the inverse, use the ~ operator.

1
2
unsigned int i = 3424;
unsigned int j = ~i;

j is 42924963871


EDIT: just as a side note:
0xffffffff - 0x00000d60 == ~0x00000d60
Iteresting eh?
Last edited on
Topic archived. No new replies allowed.