ok now I realize this isn't the best or most efficient or even a way that I should implement CRC32, BUT I figure if I can do it this way first then the other better ways will be easier to understand (or at the very least please afford me that discretion). I'm basically trying to compute the crc32 hash of the letter 'a' using ActionScript. So here's the code:
Code:
trace('Hash: ' + crc32('a'));

function crc32(input:String):String {
	var hexInput:String = '';
	for(var i:Number = 0; i < input.length; i++) {
		hexInput += dechex(input.charCodeAt(i));
	}
	var binaryInput:String = '';
	for(var i:Number = 0; i < hexInput.length; i++) {
		switch(hexInput.charCodeAt(i)) {
			case 48:
			binaryInput += '0000';
			break;
			case 49:
			binaryInput += '0001';
			break;
			case 50:
			binaryInput += '0010';
			break;
			case 51:
			binaryInput += '0011';
			break;
			case 52:
			binaryInput += '0100';
			break;
			case 53:
			binaryInput += '0101';
			break;
			case 54:
			binaryInput += '0110';
			break;
			case 55:
			binaryInput += '0111';
			break;
			case 56:
			binaryInput += '1000';
			break;
			case 57:
			binaryInput += '1001';
			break;
			case 97:
			binaryInput += '1010';
			break;
			case 98:
			binaryInput += '1011';
			break;
			case 99:
			binaryInput += '1100';
			break;
			case 100:
			binaryInput += '1101';
			break;
			case 101:
			binaryInput += '1110';
			break;
			case 102:
			binaryInput += '1111';
			break;
		}
	}
	var iterations:Number = binaryInput.length;
	var binaryGenerator:String = '100000100110000010001110110110111'; //Big-endian
	for(var i:Number = 0; i < binaryGenerator.length - 1; i++){
		binaryInput += '0';
	}
	for(var i:Number = 0; i < iterations; i++) {
		if(binaryInput.charAt(i) == '1') {
			for(var j:Number = 0; j < binaryGenerator.length; j++) {
				if(binaryInput.charAt(i + j) != binaryGenerator.charAt(j)){
					binaryInput = replace(binaryInput, i + j, '1');
				}else{
					binaryInput = replace(binaryInput, i + j, '0');
				}
			}
		}
		trace(i + ': ' + binaryInput);
	}
	return binaryInput.substr(binaryInput.length - (binaryGenerator.length - 1));
}

function replace(original:String, index:Number, replacement:String):String {
	if(index == 0){
		return replacement + original.substr(1);
	}
	if(index == original.length - 1){
		return original.substr(0, original.length - 1) + replacement;
	}
	return original.substr(0, index) + replacement + original.substr(index + 1);
}

function dechex(val:Number):String {
	if(val < 0){
		val += Math.pow(2, 32);
	}
	var output:String = '';
	for(var i:Number = 0; i < 8; i++){
		var remainder:Number = val % 16;
		val = (val - remainder) / 16;
		switch(remainder){
			case 10:
			output = 'a' + output;
			break;
			case 11:
			output = 'b' + output;
			break;
			case 12:
			output = 'c' + output;
			break;
			case 13:
			output = 'd' + output;
			break;
			case 14:
			output = 'e' + output;
			break;
			case 15:
			output = 'f' + output;
			break;
			default:
			output = remainder + output;
			break;
		}
	}
	do{
		if(output.charCodeAt(0) == 48){
			output = output.substr(1, output.length - 1);
		}
	}while(output.charCodeAt(0) == 48);
	return output;
}
The output of this is:
Code:
0: 0110000100000000000000000000000000000000
1: 0010000000110000010001110110110111000000
2: 0000000010101000011001001101101100100000
3: 0000000010101000011001001101101100100000
4: 0000000010101000011001001101101100100000
5: 0000000010101000011001001101101100100000
6: 0000000010101000011001001101101100100000
7: 0000000010101000011001001101101100100000
Hash: 10101000011001001101101100100000
I performed this calculation by hand and it agrees with my code. SO somewhere along the line I'm missing something I just don't know what. It may have something to do with big-endian or little-endian format. I'm hoping someone can point me in the right direction in terms of what I'm doing wrong. The actual value of the hash should be 0xe8b7be43. I also appended the hash to the original message and then computed the crc checksum of that and it resulted to 0 which implies that the calculation is correct, so why don't my hash and the ACTUAL hash agree?