DicemanX
Brain of Cthulhu
For me the Holy Grail of Terraria engineering was to find a way to convert from binary to decimal. The search has ended .
After some major inspiration earlier today I finally came up with a way to do the conversion. I posted how to convert from BCD to decimal previously, and I was able to work out a good way of converting from binary to BCD. Here's the entire converter:
Video:
I demonstrate conversion three times in the video. Each time I convert, I input the number in binary in the register first, then pull a lever to initiate the entire process. Once I finish, I pull the other lever to clear everything.
Pictures:
Explanation:
The converter consists of two mechanisms. The first converts from binary to BCD, and the second converts from BCD to decimal.
The process begins with a binary number stored in a register at the bottom right of the mechanism. Lights below the numbers 1, 2, 4, 8, 16, and 32 indicate what number is stored there, so if for instance 32, 8, and 1 are lit up, the number 32+8+1 = 41 is stored in the register.
There is a pair of wall levers near the middle right (to the right of the rightmost black display). The left lever is the clear function, turning off the 7-segment displays and turning off the numbers stored below. The right lever automates the entire conversion process from binary to decimal.
The mechanism to convert from binary to BCD is the double dabble mechanism:
http://en.wikipedia.org/wiki/Double_dabble
The algorithm is as follows:
1) if a number greater than 4 is stored in any of the 4-bit BCD displays after the shift, then 3 is added to that number.
2) double the number stored in the register (effectively shifting what's stored in each bit to the left)
Steps 1 and 2 are repeated N times, where N is the number of bits in the original register. Since my build has a 6-bit register, I need to shift 6 times.
The long track just below the two 7-segment displays is the shift mechanism. below each 7-segment display is a look-up table - if the numbers 5, 6, 7, 8, or 9 are stored in the BCD display for each digit, then 3 is added to those numbers. Each of those five values dictates what path the skeleton will take in the look-up table.
Once the double dabble protocol finishes, the BCD to binary converter kicks in. I presented this mechanism previously:
http://forums.terraria.org/index.ph...ecimal-converter-with-7-segment-display.8763/
The mechanism at the bottom right corner is a counter - it ensures that the skeletons will pass through the converter 6 times.
This converter is fully expandable. More BCD displays can be added to the left, and more BCD coverters can be added directly above as well. The starting register can be likewise expanded easily.
The best way to fully understand what's going on is to download the world that contains this converter and watch it in action.
World Download:
http://www21.zippyshare.com/v/niNq93OZ/file.html
Challenge for the group:
The display needs to be improved. The two 7-segment displays are in awkward positions. If I place them on top of the entire contraption that would allow me to squeeze them closer together but then I'd be too far from some of the skeleton paths and the skeletons would start despawning while the mechanism is running. I'd like to know if this entire mechanism can be improved/compressed.
There is also a slight problem converting any of the digits to a 5. If you download the world you'll see exactly why. There's a transition from one horizontal hoik track to a hoik track above it that results in a slight delay. I want to know if there's a better way to do the transition.
After some major inspiration earlier today I finally came up with a way to do the conversion. I posted how to convert from BCD to decimal previously, and I was able to work out a good way of converting from binary to BCD. Here's the entire converter:
Video:
I demonstrate conversion three times in the video. Each time I convert, I input the number in binary in the register first, then pull a lever to initiate the entire process. Once I finish, I pull the other lever to clear everything.
Pictures:
Explanation:
The converter consists of two mechanisms. The first converts from binary to BCD, and the second converts from BCD to decimal.
The process begins with a binary number stored in a register at the bottom right of the mechanism. Lights below the numbers 1, 2, 4, 8, 16, and 32 indicate what number is stored there, so if for instance 32, 8, and 1 are lit up, the number 32+8+1 = 41 is stored in the register.
There is a pair of wall levers near the middle right (to the right of the rightmost black display). The left lever is the clear function, turning off the 7-segment displays and turning off the numbers stored below. The right lever automates the entire conversion process from binary to decimal.
The mechanism to convert from binary to BCD is the double dabble mechanism:
http://en.wikipedia.org/wiki/Double_dabble
The algorithm is as follows:
1) if a number greater than 4 is stored in any of the 4-bit BCD displays after the shift, then 3 is added to that number.
2) double the number stored in the register (effectively shifting what's stored in each bit to the left)
Steps 1 and 2 are repeated N times, where N is the number of bits in the original register. Since my build has a 6-bit register, I need to shift 6 times.
The long track just below the two 7-segment displays is the shift mechanism. below each 7-segment display is a look-up table - if the numbers 5, 6, 7, 8, or 9 are stored in the BCD display for each digit, then 3 is added to those numbers. Each of those five values dictates what path the skeleton will take in the look-up table.
Once the double dabble protocol finishes, the BCD to binary converter kicks in. I presented this mechanism previously:
http://forums.terraria.org/index.ph...ecimal-converter-with-7-segment-display.8763/
The mechanism at the bottom right corner is a counter - it ensures that the skeletons will pass through the converter 6 times.
This converter is fully expandable. More BCD displays can be added to the left, and more BCD coverters can be added directly above as well. The starting register can be likewise expanded easily.
The best way to fully understand what's going on is to download the world that contains this converter and watch it in action.
World Download:
http://www21.zippyshare.com/v/niNq93OZ/file.html
Challenge for the group:
The display needs to be improved. The two 7-segment displays are in awkward positions. If I place them on top of the entire contraption that would allow me to squeeze them closer together but then I'd be too far from some of the skeleton paths and the skeletons would start despawning while the mechanism is running. I'd like to know if this entire mechanism can be improved/compressed.
There is also a slight problem converting any of the digits to a 5. If you download the world you'll see exactly why. There's a transition from one horizontal hoik track to a hoik track above it that results in a slight delay. I want to know if there's a better way to do the transition.
Last edited: