#!/usr/bin/perl
# Feb 14, 2005. Stephen Samuel (samuel@bcgreen.com).
#  
# 9:30PM Feb 14.  Set up BytesPerLine as an obvious control variable 
# rather than as a simple number in an if statement.
#

$BytesPerLine=4;

## More recent linux systems may require the line below 
## depending on your LOCALE 
# use bytes;


# set up the data table for the 'bits' value of each possible byte.
# Could statically load it but this really doesn't cost much.
for($i=0; $i<256; $i++){
	$bits=0;
	$n=$i;
	for( $j=0; $j<8;$j++){
		if( $n & 1 ){
			$bits++;
			# print "1";
		}else{
			$bits--;
			# print "0";
		};
		$n >>=1;
	};
	# print "   $i; $bits\n";
	$bitcount[$i]=$bits;
	$total += $bits;
};

print "checksum=$total \n";

# printf "%s\n", (join"\n",@bitcount);

# exit 0;
$sum=0;

# read and process the data.
while(<>){
	while (length($_)){
		$ch=chop;
		$sum += ($chv=$bitcount[ord($ch)]);
		$count++;
		if ( $count%$BytesPerLine == 0 ){
			printf "%d, %d\n",$count,  $sum  ;
		};
	};
};
