1331722Seadler/*
255163Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
355163Sshin * All rights reserved.
455163Sshin *
555163Sshin * Redistribution and use in source and binary forms, with or without
655163Sshin * modification, are permitted provided that the following conditions
755163Sshin * are met:
855163Sshin * 1. Redistributions of source code must retain the above copyright
955163Sshin *    notice, this list of conditions and the following disclaimer.
1055163Sshin * 2. Redistributions in binary form must reproduce the above copyright
1155163Sshin *    notice, this list of conditions and the following disclaimer in the
1255163Sshin *    documentation and/or other materials provided with the distribution.
1355163Sshin * 3. Neither the name of the project nor the names of its contributors
1455163Sshin *    may be used to endorse or promote products derived from this software
1555163Sshin *    without specific prior written permission.
1655163Sshin *
1755163Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1855163Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1955163Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2055163Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2155163Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2255163Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2355163Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2455163Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2555163Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2655163Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2755163Sshin * SUCH DAMAGE.
2855163Sshin *
2955163Sshin * $FreeBSD$
3055163Sshin */
3155163Sshin
3255163Sshin#include <stdio.h>
3355163Sshin
3455163Sshinunsigned short buf[BUFSIZ];
3555163Sshin
3655163Sshinmain()
3755163Sshin{
3855163Sshin	int	i;
3955163Sshin	unsigned short *p = buf, *q = &buf[4];
4055163Sshin	unsigned long sum, sum2;
4155163Sshin
4255163Sshin	while (scanf("%x", &i) != EOF) {
4355163Sshin		*p++ = i; printf("%d ", i);
4455163Sshin	}
4555163Sshin	printf("\n");
4655163Sshin
4755163Sshin	sum = buf[2] + (buf[3] >> 8) & 0xff;
4855163Sshin	while (q != p)
4955163Sshin		sum += (*q++ & 0xffff);
5055163Sshin	sum2 = (sum & 0xffff) + (sum >> 16) & 0xffff;
5155163Sshin	printf("%x, %x\n", sum, sum2);
5255163Sshin}
53