Something along the lines of:
\n#include <stdlib.h>\n#include <stdio.h>\n\nint main(int argc, char **argv)\n{\n unsigned char v1, v2, sum;\n unsigned int largeSum;\n \n v1 = atoi(argv[1]);\n v2 = atoi(argv[2]);\n \n sum = v1 + v2;\n largeSum = (unsigned int)v1 + (unsigned int)v2;\n \n printf("%02X + %02X = %02X (carry is %d)\\n", \n\t (unsigned int)v1, (unsigned int)v2,\n\t (unsigned int)sum, (largeSum & 0x100) != 0);\n}\n \n\n
Here is the output
\nC:\\cygwin\\home\\Arkadiy>.\\test 12 13\n0C + 0D = 19 (carry is 0)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 255 255\nFF + FF = FE (carry is 1)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 255 254\nFF + FE = FD (carry is 1)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 126 127\n7E + 7F = FD (carry is 0)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 127 127\n7F + 7F = FE (carry is 0)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 127 128\n7F + 80 = FF (carry is 0)\n\nC:\\cygwin\\home\\Arkadiy>.\\test 128 128\n80 + 80 = 00 (carry is 1)\n
Commentaries: unsigned char is used for arithmetics as it gives you modulo 255 for free. To compute carry, I use unsigned int (thus preserving the carry) and test for the value of the ninth bit using bitwise and (signed int would work too).
Note how unsigned char is cast to unsigned int in printf. I think it's necessary, because printf uses ellipsis (...) and ellipsis converts anything smaller than int to int. In the process, it may cause sign expansion (converting 0xFF to 0xFFFFFFFF). So , to be safe, we explicitly tell the compiler _how_ to convert to the int size using cast. Since we are casting from unsigned to unsigned, sign expansion does not happen.
It may be that the above is just my paranoia. But better safe than sorry. It's also possible to acheve the same result by simple bitwise anding with 0xFF in the printf statement - bitwise and with an integer converts to integer, and does it properly.
Note that I do not check if argv[1] or [2] are present. Not a good thing to do for real world.