Cool algorithm for binary text string
Today’s progress was about bug fixing the block parts such as Register, Shift Register and Counter.
I simplified their code and had an idea for a better way to display number values. Basically, the default is 8-bit data, but it may be up to 16-bit which allows for when we do arithmetic such as multiplication. And we may set a preference for 4-bit nibbles, yet have the size expand out to accommodate larger numbers when displaying them for a Bus for example.
This is easy to do with say a hex format string such as 0x%02X
which will show at least 2 significant digits, but will expand out to 4 digits if need be.
For the binary text function I came up with this code:
# Create groups of 4 bits
func int2bin(x: int, num_bits = 8) -> String:
var _b = ""
for n in 16:
if n > 0 and n % 4 == 0:
if x == 0 and n == num_bits:
break
_b = " " + _b
_b = String(x % 2) + _b
x /= 2
return "0b" + _b
This groups binary digits into space-separated chunks of 4 digits and has a minimum bit length.
Have to test the ALU block next.
More Devlog entries
Most recent first
- 2021 10 02 New Release of Digital Logic Simulator
- 2021 08 28 Nested Sub Blocks
- 2021 08 27 Debugging with a log file
- 2021 08 26 Testing Circuit Blocks
- 2021 08 24 Bug Fixing with Blocks
- 2021 08 22 Debugging Circuit Blocks
- 2021 08 21 Circuit Blocks Update
- 2021 08 18 Circuit Blocks
- 2021 08 16 Highlighting of wires
- 2021 08 12 Adding Tutorial Content
- 2021 08 07 Numbers Scene
- 2021 08 06 Numbers Tabbed Scene
- 2021 08 04 Number Display Widget
- 2021 07 26 Logic Simulator Update
- 2021 07 24 - Launch of V1.0
- 2021 07 23 - Truth Tables
- 2021 07 22 Progress Update
- 2021 07 21 - Simple Computer Simulation
- 2021 07 16 - Community Forum
- 2021 07 15 - Community News
- 2021 07 11 - Save and Load ROM Data
- 2021 07 09 - Documentation About The Logic Simulator
- 2021 07 08 - Big Progress
- 2021 07 07 - RAM and ROM Testing Complete
- 2021 07 06 - Implementing Tests
- 2021 07 04 - Debugging Complex Situations
- 2021 06 30 - End of June - Refactoring Continues
- 2021 06 29 Community
- 2021 06 28 Implementing More OOP
- 2021 06 27 Memory Parts
- 2021 06 26 Improving the Memory Manager
- 2021 06 25 Memory Data
- 2021 06 24 Memory Management
- 2021 06 23 First Devlog Entry