/*
 * decimate.c
 * Simulate the mathematical operations carried out
 * by a sinc^4 decimator with a decimation factor of 32.
 *
 * The decimator uses modulo 2^24 arithmetic to do
 * its calculations.
 *
 * R. Schreier of OSU, 1993.
 */ 

#define R 32
#define N 24

static int Modulus = 1<<N;
static int Signbit = 1<<(N-1);
static int Mask = (1<<N)-1;

int mod( int x ){
    return x&Mask;
    }

main(){
/* Declarations. */
int a1=0, a2=0, a3=0, a4=0, s1=0, s2=0, s3=0, s4=0;
int t, x, y1, y2, y3, y4;

/*
printf("Signbit = %.8x\n", Signbit );
printf("Mask = %.8x\n", Mask );
*/

/* Get the input and go through the equations. */
for(t=0; scanf("%d",&x) > 0; ){
    a1 = mod( a1 + x );
    a2 = mod( a2 + a1 );
    a3 = mod( a3 + a2 );
    a4 = mod( a4 + a3 );
    if( ++t == R ){
        t = 0;
        y1 = mod( a4 - s1 );
        s1 = a4;
        y2 = mod( y1 - s2 );
        s2 = y1;
        y3 = mod( y2 - s3 );
        s3 = y2;
        y4 = mod( y3 - s4 );
        s4 = y3;
        if( y4 & Signbit )
            printf( "%d\n", y4 - Modulus );
        else
            printf( "%d\n", y4 );
        }
    }
exit(0);
}

