Number conversions component tutorial

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Number conversions component tutorial

Post 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 9014 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 780 times
The finished exported component file is available here.
NumberHelper.fcpx
(2.09 KiB) Downloaded 645 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?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Number conversions component tutorial

Post by QMESAR »

Great stuff Ben thank you very much :D

alanwms
Posts: 67
Joined: Tue Sep 16, 2008 2:09 pm
Location: Minnesota USA
Has thanked: 4 times
Been thanked: 17 times
Contact:

Re: Number conversions component tutorial

Post by alanwms »

Can't see anything clear on the video. Not sure what value it has.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Number conversions component tutorial

Post by Benj »

Hello,

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

rafaeltgross
Posts: 7
Joined: Wed Apr 21, 2021 8:37 am
Contact:

Re: Number conversions component tutorial

Post 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

Post Reply