How to convert Hex values to Binary or Decimal using C/C++

Status
Not open for further replies.
Re: How to convert Hex values to Binary or Decimal using C/C

Try:

/* Let hex value in micro be num, divide by 10 and keep remainder, call it value */

value = num % 10;

num /= 10;

/* Carry on till value become Zero! */
 

Re: How to convert Hex values to Binary or Decimal using C/C

ok Here you go: You can build and debug in Keil!

/* Prototype */
void Hex2Decimal(unsigned long num);

/* Hex Variable in any register */
unsigned long num = 0x499602D2 ; /* 1234567890 */

int main (void)
{
Hex2Decimal(num); /* Convert given hex to decimal digits */

return 1; /* Good C!, not required */
}

/* Function */

/* Converts an unsigned hex number availabe in the micro registers to decimal digits
and stores the decimal digits in an array */
void Hex2Decimal(unsigned long num)
{
unsigned char value[10];
unsigned char i = 0;

while(num > 0)
{
value = num % 10;
num /= 10;
i = i + 1;
}
}
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…