binary arithmetic Flashcards
(4 cards)
1
Q
Binary addition
A
0+0=0 0+1=1 1+0=1 1 + 1 = 0 with carry Carry + 0 + 0 = 1 Carry + 0 + 1 = 0 with carry Carry + 1 + 0 = 0 with carry Carry + 1 + 1 = 1 with carry
2
Q
Binary Subtract
A
0−0=0 0 − 1 = 1 with a borrow 1−0=1 1−1=0 0 − 0 − borrow = 1 with a borrow 0 − 1 − borrow = 0 with a borrow 1 − 0 − borrow = 0 1 − 1 − borrow = 1 with a borrow
3
Q
Binary multiplication
A
like with decimal, but with shifting the result every time and having an addition of the partial results.
4
Q
Modulo-N counters
A
Number sequences starting from zero to MAX_VALUE:
0 .. 1..2..Nmax-1.. 0 .. 1.. 2 and then again starting from zero. (like transaction log id):
cntr = (cntr + 1 ) % n; cntr = (cntr + 1) & 0x3f;