Stormworks: Build and Rescue

Stormworks: Build and Rescue

Not enough ratings
Decimal to Binary Converter
   
Award
Favorite
Favorited
Unfavorite
Microcontrollers: Calculation, Microcontroller
Tags: v1.0.19
File Size
Posted
31.525 KB
Oct 26, 2020 @ 5:45am
1 Change Note ( view )

Subscribe to download
Decimal to Binary Converter

Description
Converts a decimal value to a 9-bit binary output.

Since there are 9 bits, the decimal value range is 0-511 for 512 different on/off switch combinations. This is *extremely* useful if trying to manage a series of complex on/off switches.

In my case, I had a LUA Display Menu with 10 different pages. Which of the 10 pages is currently active on the display is controlled by a series of 9 video switchboxes. So I needed 9 different combinations of on/off switches in order to get the 10 different pages to display.

I assigned each of the 9 different switchboxes to a bit position so I can use a single decimal value to set the correct combination of 9 switches for the page I want to display.

So, I set the value "0" to my Main Menu, and I have 9 different pages that I can put on the display. Also interesting to see the simple LUA formula used to convert decimal value to a 9-bit array. So the "decToBin" function embedded in the LUA block is also transportable to your LUA blocks!



1 Comments
Nom du profil Jan 16, 2021 @ 8:31pm 
You can do the Binary to Decimal?