In this article, it says the following:
1111 + 0001 = 0000 (carry flag is turned on)
As far as I know, a carry happens when the result does not fit in a certain number of bits (4 bits in this example), so the above equation indeed caused a carry (because the result is in effect 10000, which does not fit in 4 bits).
But look at the following from the same article:
0000 - 0001 = 1111 (carry flag is turned on)
I don't understand why the carry flag is set in this case, I mean the result is 1111, so it fits in 4 bits!
If you disregard the size of the type, then
That is why you get a carry (simply to indicate that the result is larger than the stored 0). This is important if you must add additional (hex) "digits".
With subtraction, you can get a similar problem:
That actually says: 0 - 1 = 15. That is not true, so the carry is set to indicate that a borrow was performed, i.e. that, more or less, the following is performed:
You do the same when you subtract in decimal:
To subtract 8 from 4, you must borrow 1 from the next digit, to get 14 − 8 = 6. That borrow is needed to get the subtraction of the next pair of higher digits right. 3 − 1 = 2, but you must subtract the borrow too, so now 3 − 1 − borrow = 1. That is why you (correctly) get 16 and not 26 as a result.
The binary borrow has the same function: it is stored in the carry flag and can be subtracted (e.g. in x86 assembler), using
SBB(subtract with borrow) instead of a plainSUB(subtract). The value of the carry flag (which is functioning as a "borrow flag" now) is additionally subtracted from the two operands: