pyrohaz - if we work through your proposal:

A = 200

B = 40

result = A - B

= 200 + (255-40)

= 200 (1100100) + 215 (11010111)

= 415 (110011111)

masked to 8 bits = 10011111 = 159

which is incorrect.

The number 215 is suspicious.

In binary, the bottom binary digit (bit) of a number determines if the number is odd or even.

Adding or subtracting two even numbers always produces an even number, so 200-40 must be even.

The operation 255-40 converts an even number to an odd number, so it is either wrong, or there are other steps missing from the algorithm.

As mlundinse has explained, taking the two's complement, is 256-x, and that does produce the correct binary value.

Geting the two's complement is straightforward, and does not need the subtraction operation.

Two's complement: flip all the bits and add one.

Example 40: (00101000)

-> flip all the bits (1's complement) = 11010111

-> add 1 to 11010111 = 11011000 (216)

Those operations are easy to implement (there must be an add implemented :-)

An important point which needs reinforcing is, the electronics to do the bit operations on the numbers for signed and unsigned binary addition is the same. The difference is how carry or overflow is interpreted.

So the nifty part is subtraction **is** addition using the two's complement of the subtrahend, even for unsigned arithmetic.

Addition is the same for signed and unsigned numbers, the difference is the interpretation of the carry and top bit (sign) to identify overflow.