Is it possible to add two hexadecimal numbers in C?
If so, i would request someone to help wit the method or the logic asap.
thank you :)

Recommended Answers

All 4 Replies

>Is it possible to add two hexadecimal numbers in C?
Yes:

int a = 0xA;
int b = 0xB;

printf ( "%x\n", a + b );

yeah, thats fine. but i want to do it in graphics and so for the alignment purpose i can't do it with a printf statement!
sorry, for posting an incomplete question.

>i want to do it in graphics
Yea, that tells me absolutely nothing about your needs. Be more specific, please.

>so for the alignment purpose i can't do it with a printf statement!
Assuming you're writing this to a label or text box (or pretty much any drawing mechanism), you would use sprintf to format the string first. I don't understand what you mean by "the alignment purpose", as the printf family is fully featured when it comes to alignment formatting.

printf, as narue said, is able to format quite well.

sumValue = firstValue + secondValue;
printf("   0x%04X\n", firstValue);
printf("+  0x%04X\n", secondValue);
printf("  --------\n");
printf("   0x%04X\n", sumValue);

i think we can just this one away for free.

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.