Page 1 of 1

Number conversions component tutorial

Posted: Fri Aug 12, 2016 2:20 pm
by Benj
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.
Conversions.jpg
Conversions.jpg (10.93 KiB) Viewed 9366 times
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.
NumberConversions.fcfx
(14.72 KiB) Downloaded 795 times
The finished exported component file is available here.
NumberHelper.fcpx
(2.09 KiB) Downloaded 662 times
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?

Re: Number conversions component tutorial

Posted: Fri Aug 12, 2016 5:05 pm
by QMESAR
Great stuff Ben thank you very much :D

Re: Number conversions component tutorial

Posted: Fri Dec 09, 2016 7:16 pm
by alanwms
Can't see anything clear on the video. Not sure what value it has.

Re: Number conversions component tutorial

Posted: Sat Dec 10, 2016 3:26 pm
by Benj
Hello,

Make sure you're watching the video in fullscreen 1080p quality and the video should then be crisp.

Re: Number conversions component tutorial

Posted: Wed Apr 21, 2021 8:45 am
by rafaeltgross
Hi Ben,

Thank you very much for this great tutorial and specially for the files. It is very useful for me.

I cannot understand very clearly the video, I think if you narrate what are you doing would be much more clear, and even explain some loops.

I cannot do the 32bits challenge either. I tried changing the index to 4 bytes, the variables to ULong, the hex to x80000000, and the while loop from 16 to 32. What I'm missing?

Thanks and regards
Rafael