Or Nevo
Or Nevo

Reputation: 183

How to subtract binary when there is no where to borrow from?

Let's say I want to do the next subtraction action:

00000000 - 00000001

So when I'll try to subtract 0-1, I'll need to borrow from the left columns, but what if. like in thus case. all the next columns are zeros? Will it just be an Carry Flag exception?

Thanks.

Upvotes: 1

Views: 2402

Answers (2)

Jasen
Jasen

Reputation: 12432

or modern hardware you get the carry flag and two's complement result 1111 1111

this is why 1111 1111 is sometimes called -1

Upvotes: 0

Aki Suihkonen
Aki Suihkonen

Reputation: 20037

Almost like in modern central banking where there's no need to have money in order of money to be lent/borrowed, there's no need for the existence of a higher number either to complete any subtraction. Instead it's generated on the need.

One interpretation is that the carry is by definition the result of subtracting 1 from 0 or any number from a lesser number. (And/or adding 1 to 1 -- as explained in the other answer and the comments, subtraction is performed most oftenly as adding the two's complement of the subtractor to the subtrahend. Mathematically these are equivalent)

Another interpretation is that computer arithmetic is performed modulo 2^8 (or 2^N) which "makes the paradoxical result possible", but which doesn't solely explain the carry bit.

Upvotes: 1

Related Questions