-4
\$\begingroup\$

I am using freescaale mc9s08lg32,i want to convert the hex value from ADCR registers to decimal for sum calculation.

\$\endgroup\$
  • 2
    \$\begingroup\$ Learning the basic principles of number conversion is hardly an electrical engineering question. \$\endgroup\$ – Rev1.0 Jun 19 '13 at 7:20
  • \$\begingroup\$ Why exactly do you want this? Are you going to display it somewhere? Otherwise, see Swanand's answer. \$\endgroup\$ – user17592 Jun 19 '13 at 9:39
  • 2
    \$\begingroup\$ @Rev1.0 it happens in an EE context and is something other EEs can use as well. If something is actually pure math/programming, it can still be on topic: meta.electronics.stackexchange.com/q/2622/17592 \$\endgroup\$ – user17592 Jun 19 '13 at 9:40
  • \$\begingroup\$ @CamilStaps: Granted, that this kind of question may still be engineering related. This particular one just seemed a little bit too basic. No hard feelings ;) \$\endgroup\$ – Rev1.0 Jun 19 '13 at 12:58
  • \$\begingroup\$ Number bases 101 covered sometime in primary school. A number is a number and contains the same number of counts regardless of the base with which it is represented when written down. Changing the representation on the page is irrelevant here. \$\endgroup\$ – uɐɪ Jun 19 '13 at 13:15
1
\$\begingroup\$

You don't have to.

At the end, in Processor Core, All Calculations will be done in binary.

It doesn't matter if you do value = 0x10 + 10; value will be 26 or 0x1A or 0b11010. And this is valid for all mathematical calculations like Addition, Substraction, Multiplication, Division, Mod etc.

IMO, Number system doesn't matter for calculation.

\$\endgroup\$
  • \$\begingroup\$ if i want to multiply the register value to a number suppose '5',then how can i do it with the hex vale of the register. \$\endgroup\$ – AKO Jun 19 '13 at 7:21
  • \$\begingroup\$ @AmitKumar, just add \$\endgroup\$ – David Norman Jun 19 '13 at 7:24
  • \$\begingroup\$ @AmitKumar - When your MCU firmware gets the register value from ADCR into a working register that value in the hardware is already in a binary format of 1's and 0's. \$\endgroup\$ – Michael Karas Jun 19 '13 at 7:28
  • \$\begingroup\$ @AmitKumar As Michael said and I mentioned in answer too, Number system doesn't matter for Calculations. At the end, it's all Binary! \$\endgroup\$ – Swanand Jun 19 '13 at 7:39
  • \$\begingroup\$ The thing to realize here is, that it is the compiler that gives you the freedom to type numbers as hex, decimal or binary. 0x00, 0 or 0b00000000 respectively. \$\endgroup\$ – Rev1.0 Jun 19 '13 at 13:03
0
\$\begingroup\$

HEX is taken as a 4 bit value. So if you have 0x00, it will be 0b00000000, and if you have 0xFF it will be 0b11111111. To put this in programmatically you can either use a function which is mostly likely available in the IDE but you shouldn't have to do this you can do things directly as Swanand described

Also I'd like to add that hex values are an easy representation for humans to understand rather than reading a whole lot of zeros and ones

\$\endgroup\$
  • \$\begingroup\$ the ADCR register is giving value (482)in hex,its a 12 bit register,so can u plz tell me how can i multiply to a decimal number for further calculation \$\endgroup\$ – AKO Jun 19 '13 at 7:25
  • \$\begingroup\$ @AmitKumar, just multiply, 0x482 * 3 = 0xD86 (assming 3 is the number you want to multiply it with) \$\endgroup\$ – David Norman Jun 19 '13 at 7:28
  • \$\begingroup\$ and how to read the value of the register ADCR,actually it is showing 482 when i am debugging the code \$\endgroup\$ – AKO Jun 19 '13 at 7:35
  • \$\begingroup\$ @AmitKumar, whats connected to your ADC? \$\endgroup\$ – David Norman Jun 19 '13 at 8:14
  • \$\begingroup\$ lm 35 is connected \$\endgroup\$ – AKO Jun 19 '13 at 8:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.