I tried my best to make add and subtract numbers using FILT tmp modes, but binary addition in a series instead of parallel seems impossible. Is there a combination of FILT modes I can use to add and/or subtract numbers?
Is this what you mean?
This machine's too complicated for me to comprehend. I'll study this tech as best I can, but I'm trying to use BRAY without the 30th bit.
It's a single adder circuit that puts out the bit sums (the FILT connected to the DTEC on the right) and the bit carries (the FILT connected to the LDTC on the right). The process repeats by adding the carry bits to the sum bits until all carry bits are 0 and the calculation is finished. This means there still is some parallel processing going on in the adder circuit, but instead of running the results of the 1st adder through more adders to do the carry additions it uses a single adder in a loop.
Using BRAY (or FILT for that matter) without the 30th bit is difficult if you have to represent the number 0, because a BRAY with ctype 0 gets annihilated (each bit represents light of a specific color/frequency in the BRAY, so if no bits are set there is no color and hence no BRAY). If you set a FILT ctype to 0 the FILT goes into temperature mode (if you shine a BRAY or PHOT through a FILT with ctype 0 the color that comes out is determined by the temperature of the FILT), so that doesn't work either.
I've created a modified version of this design:
There's even an additional FILT set by a LDTC near the final BRAY that you can mouseover to see the result. Now I just have to figure out how to subtract too; I've read that you can perform binary subtraction by adding the minuend with the 1s complement of the subtrahend (in tpt, the 1s complement of a FILT number is the result of that number passing through a NOT FILT); I've tried doing so and it didn't work, then I've tried it with the 30th bit turned off in the 1s complement number and that didn't work either.
You can do subtraction with the same design by taking the ones' complement of the minuend and the result: a - b = -(-a + b)
The ones' complement is just inverting/flipping all bits (besides the 30th bit, if you use a FILT in NOT mode you also flip the 30th bit so you should use XOR mode with ctype value 0x1FFFFFFF).
Here is a save that shows how to make a subtractor circuit from the adder by adding 2 FILT (which do the bit flips).
I've modified my design so it has addition and subtraction modes:
Now that I have and binary adder/subtractor, I can get work on making a binary multiplier/divider--you need to add and subtract before you can multiply and divide.
I've managed to quickly make a semi-functional multiplier/divider, but it has it's flaws:
The input FILT on the left is wired to the output.
To multiply, spark the multiplication button to turn on multiplication mode (it's on by default); start by setting both inputs to the same number, then spark the equals button one less time than the number you want to multiply by. For example; to multiply 2*3, set both inputs to 2 than spark the equals button 3-1 (or 2) times.
To divide, spark the division button to turn on division mode. Unfortunately, I learned the hard way that multiplying 1s complements doesn't work for division, like adding 1s complements does with subtraction. To divide to divide 6/2, I had to use the answer as the second input and this is undesirable.
Is there a better way?
Sorry for the late reaction, I was on a short holiday. The way to go with both multiplication and division is to implement long mulitiplication and long division (how you do mulitiplication and division by hand). Long multiplication in binary is exceedingly simple, the binary mulitplication table is 0*0 = 0, 1*0 = 0, 0*1 = 0, 1*1 = 1, and instead of mulitplying the addend by 10 every step you multiply by 2, which is a simple bit shift left.
The multiply algorithm looks like this:
let sum = 0 let mask = 1 // Selects the current bit in the augend let augend = A let addend = B while augend != 0 { // While there are 1-bits in the augend if (augend & mask) != 0 { // Check if the current bit is a 1-bit sum = sum + addend // If so, do an addition (multiply by 1) } // If the current bit was a 0-bit, do nothing (multiply by 0) augend = augend & ~mask // Erase the current bit from the augend mask = mask << 1 // Select the next bit addend = addend << 1 // Multiply the addend by 2 } return sum
I'll look into implementing it myself for refence but I'm a bit busy at the moment, I'll try to get it done before the weekend.
(Sorry for all the edits, formatting the pseudocode wasn't easy.)