# Conversion of hex to decimal [closed]

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

• Learning the basic principles of number conversion is hardly an electrical engineering question. – Rev1.0 Jun 19 '13 at 7:20
• Why exactly do you want this? Are you going to display it somewhere? Otherwise, see Swanand's answer. – user17592 Jun 19 '13 at 9:39
• @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 – user17592 Jun 19 '13 at 9:40
• @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 ;) – Rev1.0 Jun 19 '13 at 12:58
• 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. – uɐɪ Jun 19 '13 at 13:15

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

• 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 – AKO Jun 19 '13 at 7:25
• @AmitKumar, just multiply, 0x482 * 3 = 0xD86 (assming 3 is the number you want to multiply it with) – David Norman Jun 19 '13 at 7:28
• and how to read the value of the register ADCR,actually it is showing 482 when i am debugging the code – AKO Jun 19 '13 at 7:35
• @AmitKumar, whats connected to your ADC? – David Norman Jun 19 '13 at 8:14
• lm 35 is connected – AKO Jun 19 '13 at 8:39

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.

• 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. – AKO Jun 19 '13 at 7:21
• @AmitKumar, just add – David Norman Jun 19 '13 at 7:24
• @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. – Michael Karas Jun 19 '13 at 7:28
• @AmitKumar As Michael said and I mentioned in answer too, Number system doesn't matter for Calculations. At the end, it's all Binary! – Swanand Jun 19 '13 at 7:39
• 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. – Rev1.0 Jun 19 '13 at 13:03