#include <stdio.h>

unsigned int sum, item;
int c, pos;

main() {
	sum = 0;
	item = 0;
	pos = 0;
	printf("> ");
	while ((c = getchar()) != EOF) {
		switch (c) {
		    case '0':
			item = (item << 4) | 0;
			goto next;
		    case '1':
			item = (item << 4) | 1;
			goto next;
		    case '2':
			item = (item << 4) | 2;
			goto next;
		    case '3':
			item = (item << 4) | 3;
			goto next;
		    case '4':
			item = (item << 4) | 4;
			goto next;
		    case '5':
			item = (item << 4) | 5;
			goto next;
		    case '6':
			item = (item << 4) | 6;
			goto next;
		    case '7':
			item = (item << 4) | 7;
			goto next;
		    case '8':
			item = (item << 4) | 8;
			goto next;
		    case '9':
			item = (item << 4) | 9;
			goto next;
		    case 'A':
		    case 'a':
			item = (item << 4) | 10;
			goto next;
		    case 'B':
		    case 'b':
			item = (item << 4) | 11;
			goto next;
		    case 'C':
		    case 'c':
			item = (item << 4) | 12;
			goto next;
		    case 'D':
		    case 'd':
			item = (item << 4) | 13;
			goto next;
		    case 'E':
		    case 'e':
			item = (item << 4) | 14;
			goto next;
		    case 'F':
		    case 'f':
			item = (item << 4) | 15;
		    next:
			pos++;
			if (pos == 4) {
				pos = 0;
				sum += item;
				item = 0;
			}
			break;
		}
	}
	printf("\n");
	while (sum > 0xffff)
		sum = (sum & 0xffff) + (sum >> 16);
	if (sum == 0xffff)
		sum = 0;
	printf("checksum = %x\n", sum);
}
