Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top