Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CRC 8 bit Table calculation
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Text; namespace Rextester { public class Program { public static byte[] crctable; public static void Main(string[] args) { //Your code goes here CalulateTable_CRC8(); var sb = new StringBuilder("new byte[] { "); var sb2 = new StringBuilder("{"); foreach (var b in crctable) { sb.Append(b + ", "); sb2.AppendFormat("'{0:x2}',", b); } sb.Append("}"); sb2.Append("}"); Console.WriteLine(sb.ToString()); Console.WriteLine(sb2.ToString()); } public static void CalulateTable_CRC8() { const byte generator = 0x1D; crctable = new byte[256]; /* iterate over all byte values 0 - 255 */ for (int divident = 0; divident < 256; divident++) { byte currByte = (byte)divident; /* calculate the CRC-8 value for current byte */ for (byte bit = 0; bit < 8; bit++) { if ((currByte & 0x80) != 0) { currByte <<= 1; currByte ^= generator; } else { currByte <<= 1; } } /* store CRC value in lookup table */ crctable[divident] = currByte; } } } }
run
|
edit
|
history
|
help
0
Merge two array
Customised Code Dashboard
1
algo1
asxsdxsd
Find the missing number in an array1
array reverse
Convert string to TimeSpan in C#
Array Alternate elements
Test1