#include <stdio.h>
int
main()
{
char s1[] = "10110001";
char s2[] = "00101110";
char *p1, *p2;
int carry;
printf(" %s\n- %s\n----------\n", s1
, s2
);
p2 = s2;
while (*p2) {
if (*p2 == '0')
*p2 = '1';
else
*p2 = '0';
/* *p2 = (*p2 == '0' ? '1' : '0'); */
p2++;
}
for (p1 = s1; *p1; p1++);
for (p2 = s2; *p2; p2++);
carry = 1;
while (s1 < p1) {
p1--;
p2--;
carry += (*p1 - '0') + (*p2 - '0');
*p2 = '0' + (carry % 2);
carry /= 2;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQKbWFpbigpCnsKICBjaGFyICAgICAgICAgICAgczFbXSA9ICIxMDExMDAwMSI7CiAgY2hhciAgICAgICAgICAgIHMyW10gPSAiMDAxMDExMTAiOwogIGNoYXIgICAgICAgICAgICpwMSwgKnAyOwogIGludCAgICAgICAgICAgICBjYXJyeTsKCiAgcHJpbnRmKCIgICVzXG4tICVzXG4tLS0tLS0tLS0tXG4iLCBzMSwgczIpOwoKICBwMiA9IHMyOwogIHdoaWxlICgqcDIpIHsKICAgIGlmICgqcDIgPT0gJzAnKQogICAgICAqcDIgPSAnMSc7CiAgICBlbHNlCiAgICAgICpwMiA9ICcwJzsKICAgIC8qICpwMiA9ICgqcDIgPT0gJzAnID8gJzEnIDogJzAnKTsgKi8KICAgIHAyKys7CiAgfQoKICBmb3IgKHAxID0gczE7ICpwMTsgcDErKyk7CiAgZm9yIChwMiA9IHMyOyAqcDI7IHAyKyspOwoKICBjYXJyeSA9IDE7CiAgd2hpbGUgKHMxIDwgcDEpIHsKICAgIHAxLS07CiAgICBwMi0tOwogICAgY2FycnkgKz0gKCpwMSAtICcwJykgKyAoKnAyIC0gJzAnKTsKICAgICpwMiA9ICcwJyArIChjYXJyeSAlIDIpOwogICAgY2FycnkgLz0gMjsKICB9CgogIHByaW50ZigiPSAlc1xuIiwgczIpOwoKICByZXR1cm4gMDsKfQ==