Dear members...

I'm looking for a code in C language to calculate the sum of two number in Hexadecimal base.But I don't wanna use Math library.Please help me to do it as soon as possible...

Respectfully...

Recommended Answers

All 3 Replies

Use the "%x" descriptor.

int a=0x1c2a; //hex format
	int b=10;   //decimal format
	int c;

	c=a+b;

	printf("HEX sum: %x\n",c);
        printf("DEC sum: %d\n",c);

This will display the Hex sum: 1c34 and the Dec sum: 7220.

Dear Buffalo101

I really do appreciate...Thank you very much..The program is working fine.
But the problem is I'm trying to make a program which user able to input a two Hexadecimal number,and then the result will be the sum of those two number.
Please help me to do it.
Kind Regards...

printf and scanf take [roughly] the same set of format characters. Read the manual pages on either of the two and look for 'hex'.
Here is a starting point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.