The fundamental of logic is the Complement or NOT function. It can be done by one transistor and one input resistor. The fundamental two input AND and OR functions can be made simply using one diode for each input. By using a transistor to invert the signals gets you NAND and NOR.
There is no quick way to do MOD using electronic components. MOD is way too complicated and slow to use for making bitwise logic functions. To do MOD you must be first able to subtract which is more difficult than doing addition, or bitwise logic. So you must start construction of a calculator from the basis of having only the electronic bitwise gates = NOT, AND, OR, shift and a register to remember the bits.
From those you can next build XOR, ADD, SUB, then MUL, DIV and MOD.
Code: Select all
'=======================================================================
' Arithmetic addition by logic using only Not AND.
'=======================================================================
Function Nand(Byval a As Ulong, Byval b As Ulong) As Ulong
Nand = Not( a And b )
End Function
'-----------------------------------------------------------------------
Function Exor(Byval a As Ulong, Byval b As Ulong) As Ulong
Dim As Ulong c = Nand( a, b )
Return Nand( Nand( a, c ), Nand( b, c ) )
End Function
'-----------------------------------------------------------------------
Function Sum(Byval a As Ulong, Byval b As Ulong) As Ulong
Dim As Ulong c
Do
c = ( a And b ) Shl 1 ' carry
a = Exor( a, b ) ' sum
b = c
Loop While c
Return a
End Function
'=======================================================================
Randomize
Dim As Ulong a, b
' Do
a = Rnd * 1024
b = Rnd * 1024
' Loop While Sum( a, b ) = a + b
Print a, b, Sum( a, b ), a + b
'=======================================================================
Sleep