Original code
[code]
public string Hash(string input)
{
uint m_crc = 0xffffffff;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
bytes = encoding.GetBytes(input.ToLower());
foreach (byte myByte in bytes)
{
m_crc ^= ((uint)(myByte) << 24);
for (int i = 0; i < 8; i++)
{
if ((System.Convert.ToUInt32(m_crc) & 0x80000000) == 0x80000000)
{
m_crc = (m_crc << 1) ^ 0x04C11DB7;
}
else
{
m_crc <<= 1;
}
}
}
return String.Format(“{0:x8}”, m_crc);
}
My failing attempt in javascript… HELP!
[code]
function findCRC( string ) {
var CRC = 0xffffffff;
for ( var j = 0; j < string.length; j++ ) {
var c = string.charCodeAt(j);
CRC ^= c << 24;
for (var i = 0; i < 8; i++) {
if ( CRC & 0x800000000 )
CRC = (CRC << 1) ^ 0x04C11DB7;
else
CRC <<=1;
}
}
return CRC.toString(16);
}