Is a (01) and b (11) binary intergers, or decimal intergers?
The number a and b are meant as binary numbers. I should have written:
c = (a/2 * b/2)*2 + (a%2 * b%2); // 8 operators
c = (0 * 1)* 2 + ( 1 * 1) = 0 + 1 = 1 == 01 ==> c = b & a = 01 & 11 = 01
Also, % (modulo) is not regular math.
Since when? What is regular math according to you? intermezzo regular math?
A multiplication is a repeated addition, and an addition is a repeated increment by 1.
so in the end everything is repeated an increment by 1 (that sounds like a turing machine!!)
% can be expressed as a subtraction, division and a multiply. a % b = ( a - (a/b)*b)
c = (a/2 * b/2)*2 + (a- (a/2)*2) * (b- (b/2)*2); // 12 operators
Furthermore I assumed the integer division, which makes 1/2 => 0
So yes, I was wrong taking not enough time to explain this properly
(just like this post)
So if you want to rewrite bit operators to regular math you must first
1) isolate the individual digits
2) do the [AND-OR-XOR-NAND-....] operation
3) merge the outcomes
1 bit AND : (a*b)
1 bit OR : (a+b - (a*b))
1 bit XOR: (a+b - a*b *2)
1 bit NAND: 1-a*b
1 bit NOR: a*b - a - b
1 bit NXOR: 2*a*b -a - b
Formula's for ANDing 3 bits numbers (higher) is left as an exercise for the reader