Hi everybody
Has any one got away of converting a decimal number to hex for ARM its got to convert small numbers and large numbers. ie upto 30000
Thanks
Wayne
ARM
Moderator: Benj
-
Spanish_dude
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: ARM
if you want to convert a decimal value (int) to hex (string of 4 chars) you could do something like this :
This "dummy_var = (decimal_value >> (12 - 4 * i)) & 0x0F;" should write each nibble in dummy_var, starting from the highest nibble to the lowest one.
Code: Select all
char dummy_var = 0;
int decimal_value;
char hex_string[5] = {0};
for (i = 0; i < 4; i++)
{
dummy_var = (decimal_value >> (12 - 4 * i)) & 0x0F;
if (dummy_var < 10)
hex_string[i] = dummy_var + '0';
else
hex_string[i] = (dummy_var - 10) + 'A';
}This "dummy_var = (decimal_value >> (12 - 4 * i)) & 0x0F;" should write each nibble in dummy_var, starting from the highest nibble to the lowest one.
-
wayne millard
- Posts: 234
- Joined: Thu May 31, 2007 2:18 pm
- Has thanked: 7 times
- Been thanked: 12 times
Re: ARM
Hi Spanish Dude,
i calculate a number of counts in 1us and then need to load this into
the timer in hex
how do i pass a Flowcode Variable number to your maths.
And what is the output called is it Hex string?
Thanks
Wayne
i calculate a number of counts in 1us and then need to load this into
the timer in hex
how do i pass a Flowcode Variable number to your maths.
And what is the output called is it Hex string?
Thanks
Wayne
- 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: ARM
Hello Wayne,
You can just do it in decimal if you like. Its all the same to the uC so it doesn't matter if your using hex, binary or decimal.
0x18 is 24 in decimal.
EG
5 * 0x18 = 120
is the same as
5 * 24 = 120
And
register = 0x78
is the same as
register = 120
Hope this helps.
The Windows Calculator (calc.exe) allows you to switch between hex, decimal and binary in "programmer" mode.
You can just do it in decimal if you like. Its all the same to the uC so it doesn't matter if your using hex, binary or decimal.
0x18 is 24 in decimal.
EG
5 * 0x18 = 120
is the same as
5 * 24 = 120
And
register = 0x78
is the same as
register = 120
Hope this helps.
The Windows Calculator (calc.exe) allows you to switch between hex, decimal and binary in "programmer" mode.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel