Page 1 of 1
ARM
Posted: Tue May 03, 2011 10:01 am
by wayne millard
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
Re: ARM
Posted: Tue May 03, 2011 1:53 pm
by Spanish_dude
if you want to convert a decimal value (int) to hex (string of 4 chars) you could do something like this :
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.
Re: ARM
Posted: Tue May 03, 2011 3:16 pm
by wayne millard
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
Re: ARM
Posted: Tue May 03, 2011 3:43 pm
by wayne millard
Sorry,
What i need to do is have a decimal number then * 0x18 to load into timer overflow register.
Thanks
Wayne
Re: ARM
Posted: Tue May 03, 2011 6:02 pm
by Benj
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.