Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: a program to convert a hexadecimal number into decimal number without using %x

1. ## a program to convert a hexadecimal number into decimal number without using %x

i need a program to convert hexa decimal number to decimal number, a very simple program without using %x i have been trying to come up with a logic but couldnt do so, i wrote a program using string to take input
scanf("%s", &hexDecimal);
and then using if else conditons to do the maths like this
{
n=n-1;
x=pow(16, n);
decimalNumber[i]=0*x;
}
{,
n=n-1;
x=pow(16, n);
decimalNumber[i]=1*x;
}
and continue using such if else condition from 0-9 and then A-F which represents number bigger than 9. but i get an overflow error, so i am stuck. please anyone who can write a simple program i will be very thankful. and yeah write it in c language, thanks a lot.

• if you are using linux, then this is kinda re invnting a wheel. bash can do that
Code:
`echo \$((0x15a))`
if you really want to use c for it, then you could use strtol()
example here: http://www.cplusplus.com/reference/cstdlib/strtol/

• ## Thanks

i am using win8 and i am a beginner i just got admission in b.S.S.e in k.u so my teacher gave me this assignment to make aprogram to convert decimal binary hexadecimal and octal numbers, like we take a number from user and then convert it to the other systems, for example a user inputs a decimal number output will be its equivalent octal binary and hexadecimal number. i have written all the rest of the programs just two remaing hexadecimal to octal and hexadecimal to decimal, and yes ok i am reading the stuff on the link you gave me, if you could give me an example to implement it in my program that will be great.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•