




public class Crc32
{ uint[] table; public uint Checksum(byte[] bytes)
{ uint crc = 0xffffffff; for(int i = 0; i < bytes.Length; ++i)
{ byte index = (byte)(((crc) & 0xff) ^ bytes[i]); crc = (uint)((crc >> 8) ^ table[index]); } return ~crc; } public byte[] ChecksumBytes(byte[] bytes)
{ return BitConverter.GetBytes(Checksum(bytes)); } public Crc32()
{ uint Q= 0x12345678; table = new uint[256]; uint temp = 0; for(uint i = 0; i < table.Length; ++i)
{ temp = i; for(int j = 8; j > 0; --j)
{
if((temp & 1) == 1)
{
temp = (uint)((temp >> 1) ^ Q);
}
else
{ temp >>= 1; } } table[i] = temp; } } }
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace Test_time
{
public static class Program
{
public static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
for (int i = 0; i < 10; ++i)
{
sw.Reset();
sw.Start();
Thread.Sleep(50);
sw.Stop();
Console.WriteLine("(default) Slept for " + sw.ElapsedMilliseconds);
TimeBeginPeriod(1);
sw.Reset();
sw.Start();
Thread.Sleep(50);
sw.Stop();
TimeEndPeriod(1);
Console.WriteLine("(highres) Slept for " + sw.ElapsedMilliseconds + "\n");
}
}
[DllImport("winmm.dll", EntryPoint="timeBeginPeriod", SetLastError=true)]
private static extern uint TimeBeginPeriod(uint uMilliseconds);
[DllImport("winmm.dll", EntryPoint="timeEndPeriod", SetLastError=true)]
private static extern uint TimeEndPeriod(uint uMilliseconds);
}
}