https://www.geeksforgeeks.org/introduction-of-k-map-karnaugh-map/
https://en.wikipedia.org/wiki/Karnaugh_map
Bit integer addition. An exercise in formal logic.
a,b integer inputs
s integer sum
c carry in
cout carry out
c = 0
0 + 0 + c = 0
0 + 1 + c = 1
1 + 0 + c = 1
1 + 1 + c = 0 carry1
c = 1
0 + 0 + c = 1
0 +1 + c = 0 carry1
1 + 0 + c = 0 carry1
1 + 1 + c = 1 carry1
Truth table
a b c s cout
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
1 1 0 0 1
0 0 1 1 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1
K Maps are usefulmanual tool to dervive lagical expwerssons for comlicated logicfunctions. A truth table can represent anything, such as makingdecsions based on data base items. T and F can be used instead of 1and 0;
A brute forceappoach might be to write a logic expresson for each line in thetable and OR them.
Without resorting toK Maps by inspection.
S is true when a orb is true but not both without carry, XOR Exclusive OR .With carry it is XOR inverted.
s = (a^b) &&!c) || (!(a^b) && c))
cout is true for aand b true regardles of carry. The other cout true cinditions are (aXOR b ) AND c
cout = (a&b) ||((a^b) && c)
class bmath {
public:
int n_bits;
double dec_result,num;
unsigned long longresult, a, b;
void mult(void);
voidfrac2float(void);
void dec2bin(void);
void sub(void);
void badd(void);
};
void bmath::badd(void) {
int i;
unsigned long longmask = 1, carry = 0, c = 0, bita = 0, bitb = 0;
for (i = 0; i <n_bits; i++) {
bita = a &mask;
bitb = b &mask;
if (((bita ^ bitb)&& !carry) || (!(bita ^ bitb) && carry))c = c | mask;
if ((bita &&bitb) || ((bita ^ bitb) && carry)) carry = 1; else carry = 0;
mask <<= 1;
}//for
result = c;
}//badd()
void main(void) {
unsigned long long,a,b,x;
bmath m1;
m1.n_bits = 32
m1.a = 7;
m1.b = 7;
m1.badd();
printf(" a %lld b %lld trdult = %ll x = %lld \n", m1.a, m1.b,m1.result,x);
}//main()