0

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 :)

3
Contributors
4
Replies
6
Views
10 Years
Discussion Span
Last Post by jephthah
0

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

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

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

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.

0

>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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.