Number conversions component tutorial
Posted: Fri Aug 12, 2016 2:20 pm
Hello Everyone,
When starting out with programming the jump from Decimal to Binary can be a hard one. We have Hexadecimal which is a good way of representing binary values in short hand without having to write/count all the 1s and 0s but again converting between Hex and Decimal can be tricky.
The Windows calculator has a programmer mode which can convert between Decimal, Hex and Binary for us. However we can do the same thing using the Flowcode engine.
Here is a short tutorial on how I created a Flowcode component to provide the same Decimal, Hex and Binary conversions as provided by the calculator. This should be a handy guide for anyone using Flowcode v6 or v7 on how to add your own custom helper tools and get started with component creation. The project also contains some string manipulation routines which may be useful including hex string to number, binary string to number and number to binary string conversions.
[/youtube]
The source code for the project is available here. The finished exported component file is available here. As the macros and variables in the component are all only called from a simulation event none of the code will end up being added to the generated C code. So you can add this component to any project you need without worrying about it consuming any precious memory on your microcontroller.
For a challenge why not try increasing the efficiency of the component, are all those variables needed? Also what about supporting 32-bit numbers?
When starting out with programming the jump from Decimal to Binary can be a hard one. We have Hexadecimal which is a good way of representing binary values in short hand without having to write/count all the 1s and 0s but again converting between Hex and Decimal can be tricky.
The Windows calculator has a programmer mode which can convert between Decimal, Hex and Binary for us. However we can do the same thing using the Flowcode engine.
Here is a short tutorial on how I created a Flowcode component to provide the same Decimal, Hex and Binary conversions as provided by the calculator. This should be a handy guide for anyone using Flowcode v6 or v7 on how to add your own custom helper tools and get started with component creation. The project also contains some string manipulation routines which may be useful including hex string to number, binary string to number and number to binary string conversions.
[/youtube]
The source code for the project is available here. The finished exported component file is available here. As the macros and variables in the component are all only called from a simulation event none of the code will end up being added to the generated C code. So you can add this component to any project you need without worrying about it consuming any precious memory on your microcontroller.
For a challenge why not try increasing the efficiency of the component, are all those variables needed? Also what about supporting 32-bit numbers?