keyboard_arrow_left Previous
Next keyboard_arrow_right
How to use comparators for basic maths (add and substract)
Basic notions:
The comparator is a redstone component which has two mode : - compare : return input if control < input else return 0- substract : return input - controlFor example.for input = 14 and control = 13 , a comparator returns 14 in compare mode and 1 in substract mode.(note : you can use F3 to see the redstone wire power [at the right] ) How to add in minecraft?
--> by substracting !
Indeed , in maths A-(-B) = A+B
However in Minecraft if A = 2 and B = 10 , A-(-B) = 2-(0) = 2 because restone works on base16 (from 0 to 15).
How to fix that ?
--> a little trick
We know that 15 - 15 = 0 And A-(-B) = A+B.
So 15 - (15 - A - B) = 15 -15 + A + B = A+B
with A = 2 and B = 10 we have : 15 -(15 -A-B) = 15-(15-2-10) = 15-(3) = 12
With redstone :
However if A + B > 15 it doesn't work:
for example : A = 8 , B = 10
15 - (15-A-B) = 15-(15-8-10) = 15-(7-10) = 15- 0 = 15
How to add to numbers A and B with A+B > 15 ?
in fact , it's a bit tricky because we need few modules.
First we need to create a module which performs the following:
for 2 inputs A and B and 2 outputs C and D.
C = A + B
if C > 15 , C = 15
D = A + B - 15
if D < 0 , D = 0
With comparators:
C = 15 - (15 - A - B)
D = B - (15 - A)
[let's call it the 'Splitter']
Then We need to put C and D in base 10, that's to say we need a module which perfoms the following :
for C an input , Ca and Cb two outputs.
Cb = 0 if C < 10 , else Cb = 1
Ca = C if C < 10, else C - 10
(do the same for D)
In Minecraft :
(note : Cb = 15 if C >=10 and need to be fixed at 1. just need to do Cb - 14)
Assembling:
A and B , two numbers to add.
first , use the splitter . [A & B -> C & D]
Then put both outputs in base 10. [C -> Ca & Cb ; D -> Da & Db].
let's Xa = 15 - (15 - Ca - Da) (use the basic adding system)
Then put Xa in base 10. [Xa -> Xaa & Xab].
Finally : Out1 = Xaa and Out2 = 15 - (15 - Cb - Db - Xab )
Tadaa !!
A + B = Out1 + 10 * Out2
An example :
A = 8 , B = 10
splitter -> C = 15 , D = 3
base 10 -> Ca = 5 , Cb = 1 , Da = 3 , Db = 0
Xa = 5 + 3 = 8
base 10 -> Xaa = 8 , Xab = 0
-> Out1 = 8 , Out2 = 1 + 0 + 0 = 1
A + B = 18
Out1 + 10*Out2 = 18 , Ok !
The Entire system :
How to build it , layer by layer :
hoppers : 3 * 64 items on the left , 3*64 +32 items on the right
hoppers at the top : 3 * 64 +32 items on the left , 3*64 items on the right
hoppers at the bottom : 3 * 64 items on the left , 3*64 +32 items on the right
hopper : 1 item
hopper : 1 item
hopper : 1 item
tracking
4366577
how-to-use-comparators-for-basic-maths-add-and-substract
1,165079,329,140820,559826,842002,64651,214207,712893,356071,290694,1030646,15493,171513,336698,476982,98449,817406,209568,526780,928263,1263961,2177557,1579022,3,1465603
0 replies