-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of ssh://github.com/squirrely/arinc_838
* 'master' of ssh://github.com/squirrely/arinc_838: Added the 64CRC table generator as proof of static table. Commented out to use faster static table.[25614187] Created Crc64Generator. Added CRC 64 expected values to CRC_Expected_Values.xml. Added CRC 32 table generating code. [#25614187] Created Crc16Generator and Crc32Generator classes [#25614187]
- Loading branch information
Showing
8 changed files
with
427 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
public class Crc16Generator { | ||
|
||
public static int calculateCrc(byte[] bytes) { | ||
int crc = 0xFFFF; // initial value | ||
int polynomial = 0x1021; // 0001 0000 0010 0001 (0, 5, 12) | ||
|
||
for (byte b : bytes) { | ||
for (int i = 0; i < 8; i++) { | ||
boolean bit = ((b >> (7 - i) & 1) == 1); | ||
boolean c15 = ((crc >> 15 & 1) == 1); | ||
crc <<= 1; | ||
if (c15 ^ bit) | ||
crc ^= polynomial; | ||
} | ||
} | ||
|
||
crc &= 0xffff; | ||
return crc; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
public class Crc32Generator { | ||
|
||
static int[] table = { | ||
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, | ||
0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, | ||
0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, | ||
0x384FBDBD, 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, | ||
0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, | ||
0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, | ||
0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, | ||
0x95609039, 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, | ||
0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, | ||
0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, | ||
0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, | ||
0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, | ||
0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, | ||
0x30476DC0, 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, | ||
0x2E003DC5, 0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, | ||
0x1FCDBB16, 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, | ||
0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, | ||
0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, | ||
0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, | ||
0x40D816BA, 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, | ||
0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, | ||
0x8E6C3698, 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, | ||
0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, | ||
0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, | ||
0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, | ||
0xD1799B34, 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, | ||
0x608EDB80, 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, | ||
0x774BB0EB, 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, | ||
0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, | ||
0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, | ||
0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, | ||
0x0E56F0FF, 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, | ||
0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, | ||
0xE6EA3D65, 0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, | ||
0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, | ||
0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, | ||
0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, | ||
0x9FF77D71, 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, | ||
0x81B02D74, 0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, | ||
0x50C9B640, 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, | ||
0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, | ||
0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, | ||
0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, | ||
0x0FDC1BEC, 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, | ||
0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, | ||
0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, | ||
0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, | ||
0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, | ||
0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, | ||
0x9E7D9662, 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, | ||
0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, | ||
0xB1F740B4 }; | ||
|
||
// Generates CRC lookup table above. Ported from C code in spec. | ||
// static { | ||
// long generator = 0x04C11DB7; | ||
// for(int i=0; i < 256; i++) { | ||
// int shift_reg = i << 24; | ||
// for(int k=7; k>=0; k--) { | ||
// long leading_bit = shift_reg & 0x80000000; | ||
// shift_reg <<= 1; | ||
// if (leading_bit != 0) { | ||
// shift_reg ^= generator; | ||
// } | ||
// } | ||
// table[i] = shift_reg; | ||
// } | ||
// } | ||
|
||
|
||
public static long calculateCrc(byte[] bytes) { | ||
int crc = 0xffffffff; | ||
int k; | ||
for (byte b : bytes) { | ||
k = ((crc >>> 24) ^ b) & 0xff; | ||
crc = (crc << 8) ^ table[k]; | ||
} | ||
|
||
crc ^= 0xFFFFFFFF; | ||
long result = 0x00000000FFFFFFFFl & crc; | ||
return result; | ||
} | ||
|
||
} |
195 changes: 195 additions & 0 deletions
195
src/main/java/edu/cmu/sv/arinc838/crc/Crc64Generator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
public class Crc64Generator { | ||
|
||
|
||
|
||
static int[] tableHigh = { 0x00000000, 0x42F0E1EB, 0x85E1C3D7, | ||
0xC711223C, 0x49336645, 0x0BC387AE, 0xCCD2A592, 0x8E224479, | ||
0x9266CC8A, 0xD0962D61, 0x17870F5D, 0x5577EEB6, 0xDB55AACF, | ||
0x99A54B24, 0x5EB46918, 0x1C4488F3, 0x663D78FF, 0x24CD9914, | ||
0xE3DCBB28, 0xA12C5AC3, 0x2F0E1EBA, 0x6DFEFF51, 0xAAEFDD6D, | ||
0xE81F3C86, 0xF45BB475, 0xB6AB559E, 0x71BA77A2, 0x334A9649, | ||
0xBD68D230, 0xFF9833DB, 0x388911E7, 0x7A79F00C, 0xCC7AF1FF, | ||
0x8E8A1014, 0x499B3228, 0x0B6BD3C3, 0x854997BA, 0xC7B97651, | ||
0x00A8546D, 0x4258B586, 0x5E1C3D75, 0x1CECDC9E, 0xDBFDFEA2, | ||
0x990D1F49, 0x172F5B30, 0x55DFBADB, 0x92CE98E7, 0xD03E790C, | ||
0xAA478900, 0xE8B768EB, 0x2FA64AD7, 0x6D56AB3C, 0xE374EF45, | ||
0xA1840EAE, 0x66952C92, 0x2465CD79, 0x3821458A, 0x7AD1A461, | ||
0xBDC0865D, 0xFF3067B6, 0x711223CF, 0x33E2C224, 0xF4F3E018, | ||
0xB60301F3, 0xDA050215, 0x98F5E3FE, 0x5FE4C1C2, 0x1D142029, | ||
0x93366450, 0xD1C685BB, 0x16D7A787, 0x5427466C, 0x4863CE9F, | ||
0x0A932F74, 0xCD820D48, 0x8F72ECA3, 0x0150A8DA, 0x43A04931, | ||
0x84B16B0D, 0xC6418AE6, 0xBC387AEA, 0xFEC89B01, 0x39D9B93D, | ||
0x7B2958D6, 0xF50B1CAF, 0xB7FBFD44, 0x70EADF78, 0x321A3E93, | ||
0x2E5EB660, 0x6CAE578B, 0xABBF75B7, 0xE94F945C, 0x676DD025, | ||
0x259D31CE, 0xE28C13F2, 0xA07CF219, 0x167FF3EA, 0x548F1201, | ||
0x939E303D, 0xD16ED1D6, 0x5F4C95AF, 0x1DBC7444, 0xDAAD5678, | ||
0x985DB793, 0x84193F60, 0xC6E9DE8B, 0x01F8FCB7, 0x43081D5C, | ||
0xCD2A5925, 0x8FDAB8CE, 0x48CB9AF2, 0x0A3B7B19, 0x70428B15, | ||
0x32B26AFE, 0xF5A348C2, 0xB753A929, 0x3971ED50, 0x7B810CBB, | ||
0xBC902E87, 0xFE60CF6C, 0xE224479F, 0xA0D4A674, 0x67C58448, | ||
0x253565A3, 0xAB1721DA, 0xE9E7C031, 0x2EF6E20D, 0x6C0603E6, | ||
0xF6FAE5C0, 0xB40A042B, 0x731B2617, 0x31EBC7FC, 0xBFC98385, | ||
0xFD39626E, 0x3A284052, 0x78D8A1B9, 0x649C294A, 0x266CC8A1, | ||
0xE17DEA9D, 0xA38D0B76, 0x2DAF4F0F, 0x6F5FAEE4, 0xA84E8CD8, | ||
0xEABE6D33, 0x90C79D3F, 0xD2377CD4, 0x15265EE8, 0x57D6BF03, | ||
0xD9F4FB7A, 0x9B041A91, 0x5C1538AD, 0x1EE5D946, 0x02A151B5, | ||
0x4051B05E, 0x87409262, 0xC5B07389, 0x4B9237F0, 0x0962D61B, | ||
0xCE73F427, 0x8C8315CC, 0x3A80143F, 0x7870F5D4, 0xBF61D7E8, | ||
0xFD913603, 0x73B3727A, 0x31439391, 0xF652B1AD, 0xB4A25046, | ||
0xA8E6D8B5, 0xEA16395E, 0x2D071B62, 0x6FF7FA89, 0xE1D5BEF0, | ||
0xA3255F1B, 0x64347D27, 0x26C49CCC, 0x5CBD6CC0, 0x1E4D8D2B, | ||
0xD95CAF17, 0x9BAC4EFC, 0x158E0A85, 0x577EEB6E, 0x906FC952, | ||
0xD29F28B9, 0xCEDBA04A, 0x8C2B41A1, 0x4B3A639D, 0x09CA8276, | ||
0x87E8C60F, 0xC51827E4, 0x020905D8, 0x40F9E433, 0x2CFFE7D5, | ||
0x6E0F063E, 0xA91E2402, 0xEBEEC5E9, 0x65CC8190, 0x273C607B, | ||
0xE02D4247, 0xA2DDA3AC, 0xBE992B5F, 0xFC69CAB4, 0x3B78E888, | ||
0x79880963, 0xF7AA4D1A, 0xB55AACF1, 0x724B8ECD, 0x30BB6F26, | ||
0x4AC29F2A, 0x08327EC1, 0xCF235CFD, 0x8DD3BD16, 0x03F1F96F, | ||
0x41011884, 0x86103AB8, 0xC4E0DB53, 0xD8A453A0, 0x9A54B24B, | ||
0x5D459077, 0x1FB5719C, 0x919735E5, 0xD367D40E, 0x1476F632, | ||
0x568617D9, 0xE085162A, 0xA275F7C1, 0x6564D5FD, 0x27943416, | ||
0xA9B6706F, 0xEB469184, 0x2C57B3B8, 0x6EA75253, 0x72E3DAA0, | ||
0x30133B4B, 0xF7021977, 0xB5F2F89C, 0x3BD0BCE5, 0x79205D0E, | ||
0xBE317F32, 0xFCC19ED9, 0x86B86ED5, 0xC4488F3E, 0x0359AD02, | ||
0x41A94CE9, 0xCF8B0890, 0x8D7BE97B, 0x4A6ACB47, 0x089A2AAC, | ||
0x14DEA25F, 0x562E43B4, 0x913F6188, 0xD3CF8063, 0x5DEDC41A, | ||
0x1F1D25F1, 0xD80C07CD, 0x9AFCE626 }; | ||
|
||
public static int[] tableLow = { 0x00000000, 0xA9EA3693, 0x53D46D26, | ||
0xFA3E5BB5, 0x0E42ECDF, 0xA7A8DA4C, 0x5D9681F9, 0xF47CB76A, | ||
0x1C85D9BE, 0xB56FEF2D, 0x4F51B498, 0xE6BB820B, 0x12C73561, | ||
0xBB2D03F2, 0x41135847, 0xE8F96ED4, 0x90E185EF, 0x390BB37C, | ||
0xC335E8C9, 0x6ADFDE5A, 0x9EA36930, 0x37495FA3, 0xCD770416, | ||
0x649D3285, 0x8C645C51, 0x258E6AC2, 0xDFB03177, 0x765A07E4, | ||
0x8226B08E, 0x2BCC861D, 0xD1F2DDA8, 0x7818EB3B, 0x21C30BDE, | ||
0x88293D4D, 0x721766F8, 0xDBFD506B, 0x2F81E701, 0x866BD192, | ||
0x7C558A27, 0xD5BFBCB4, 0x3D46D260, 0x94ACE4F3, 0x6E92BF46, | ||
0xC77889D5, 0x33043EBF, 0x9AEE082C, 0x60D05399, 0xC93A650A, | ||
0xB1228E31, 0x18C8B8A2, 0xE2F6E317, 0x4B1CD584, 0xBF6062EE, | ||
0x168A547D, 0xECB40FC8, 0x455E395B, 0xADA7578F, 0x044D611C, | ||
0xFE733AA9, 0x57990C3A, 0xA3E5BB50, 0x0A0F8DC3, 0xF031D676, | ||
0x59DBE0E5, 0xEA6C212F, 0x438617BC, 0xB9B84C09, 0x10527A9A, | ||
0xE42ECDF0, 0x4DC4FB63, 0xB7FAA0D6, 0x1E109645, 0xF6E9F891, | ||
0x5F03CE02, 0xA53D95B7, 0x0CD7A324, 0xF8AB144E, 0x514122DD, | ||
0xAB7F7968, 0x02954FFB, 0x7A8DA4C0, 0xD3679253, 0x2959C9E6, | ||
0x80B3FF75, 0x74CF481F, 0xDD257E8C, 0x271B2539, 0x8EF113AA, | ||
0x66087D7E, 0xCFE24BED, 0x35DC1058, 0x9C3626CB, 0x684A91A1, | ||
0xC1A0A732, 0x3B9EFC87, 0x9274CA14, 0xCBAF2AF1, 0x62451C62, | ||
0x987B47D7, 0x31917144, 0xC5EDC62E, 0x6C07F0BD, 0x9639AB08, | ||
0x3FD39D9B, 0xD72AF34F, 0x7EC0C5DC, 0x84FE9E69, 0x2D14A8FA, | ||
0xD9681F90, 0x70822903, 0x8ABC72B6, 0x23564425, 0x5B4EAF1E, | ||
0xF2A4998D, 0x089AC238, 0xA170F4AB, 0x550C43C1, 0xFCE67552, | ||
0x06D82EE7, 0xAF321874, 0x47CB76A0, 0xEE214033, 0x141F1B86, | ||
0xBDF52D15, 0x49899A7F, 0xE063ACEC, 0x1A5DF759, 0xB3B7C1CA, | ||
0x7D3274CD, 0xD4D8425E, 0x2EE619EB, 0x870C2F78, 0x73709812, | ||
0xDA9AAE81, 0x20A4F534, 0x894EC3A7, 0x61B7AD73, 0xC85D9BE0, | ||
0x3263C055, 0x9B89F6C6, 0x6FF541AC, 0xC61F773F, 0x3C212C8A, | ||
0x95CB1A19, 0xEDD3F122, 0x4439C7B1, 0xBE079C04, 0x17EDAA97, | ||
0xE3911DFD, 0x4A7B2B6E, 0xB04570DB, 0x19AF4648, 0xF156289C, | ||
0x58BC1E0F, 0xA28245BA, 0x0B687329, 0xFF14C443, 0x56FEF2D0, | ||
0xACC0A965, 0x052A9FF6, 0x5CF17F13, 0xF51B4980, 0x0F251235, | ||
0xA6CF24A6, 0x52B393CC, 0xFB59A55F, 0x0167FEEA, 0xA88DC879, | ||
0x4074A6AD, 0xE99E903E, 0x13A0CB8B, 0xBA4AFD18, 0x4E364A72, | ||
0xE7DC7CE1, 0x1DE22754, 0xB40811C7, 0xCC10FAFC, 0x65FACC6F, | ||
0x9FC497DA, 0x362EA149, 0xC2521623, 0x6BB820B0, 0x91867B05, | ||
0x386C4D96, 0xD0952342, 0x797F15D1, 0x83414E64, 0x2AAB78F7, | ||
0xDED7CF9D, 0x773DF90E, 0x8D03A2BB, 0x24E99428, 0x975E55E2, | ||
0x3EB46371, 0xC48A38C4, 0x6D600E57, 0x991CB93D, 0x30F68FAE, | ||
0xCAC8D41B, 0x6322E288, 0x8BDB8C5C, 0x2231BACF, 0xD80FE17A, | ||
0x71E5D7E9, 0x85996083, 0x2C735610, 0xD64D0DA5, 0x7FA73B36, | ||
0x07BFD00D, 0xAE55E69E, 0x546BBD2B, 0xFD818BB8, 0x09FD3CD2, | ||
0xA0170A41, 0x5A2951F4, 0xF3C36767, 0x1B3A09B3, 0xB2D03F20, | ||
0x48EE6495, 0xE1045206, 0x1578E56C, 0xBC92D3FF, 0x46AC884A, | ||
0xEF46BED9, 0xB69D5E3C, 0x1F7768AF, 0xE549331A, 0x4CA30589, | ||
0xB8DFB2E3, 0x11358470, 0xEB0BDFC5, 0x42E1E956, 0xAA188782, | ||
0x03F2B111, 0xF9CCEAA4, 0x5026DC37, 0xA45A6B5D, 0x0DB05DCE, | ||
0xF78E067B, 0x5E6430E8, 0x267CDBD3, 0x8F96ED40, 0x75A8B6F5, | ||
0xDC428066, 0x283E370C, 0x81D4019F, 0x7BEA5A2A, 0xD2006CB9, | ||
0x3AF9026D, 0x931334FE, 0x692D6F4B, 0xC0C759D8, 0x34BBEEB2, | ||
0x9D51D821, 0x676F8394, 0xCE85B507 }; | ||
|
||
public static long calculateCrc(byte[] buffer) { | ||
long low = 0xFFFFFFFFl, high = 0xFFFFFFFFl; | ||
int index; // Index into table | ||
long tempLow; // A working temporary | ||
long tempHigh; // A working temporary | ||
|
||
// Loop for each byte in buffer | ||
for (int i = 0; i < buffer.length; i++) { | ||
// Compute the table index for this byte | ||
index = (int) (((high >> 24) ^ (int) buffer[i]) & 0xFF); | ||
// Update the running crc | ||
|
||
tempHigh = ((high << 8) | ((low >> 24) & 0x000000FFl)) & 0xFFFFFFFFl; | ||
tempLow = (low << 8) & 0xFFFFFFFFl; | ||
|
||
high = (tempHigh ^ tableHigh[index]) & 0xFFFFFFFFl; | ||
low = (tempLow ^ tableLow[index]) & 0xFFFFFFFFl; | ||
} | ||
|
||
high ^= 0xFFFFFFFFl; | ||
low ^= 0xFFFFFFFFl; | ||
return low | (high << 32); | ||
} | ||
|
||
/* | ||
* Generates CRC lookup table above. Ported from C code in spec. | ||
static int[] tableHigh = new int[256]; | ||
static int[] tableLow = new int[256]; | ||
static int regHigh; | ||
static int regLow; | ||
static { | ||
// Loop for each possible byte value | ||
for (int iByteVal=0; iByteVal < 256; iByteVal++) { | ||
// Make the Table entry for the current byte value | ||
MakeTableEntry(iByteVal); | ||
tableHigh[iByteVal] = regHigh; | ||
tableLow[iByteVal] = regLow; | ||
} | ||
// PrintTable(); // Comment out if desired | ||
} | ||
static void MakeTableEntry(int byteVal) | ||
{ | ||
int generatorLow = 0xA9EA3693; | ||
int generatorHigh = 0x42F0E1EB; | ||
regHigh = byteVal << 24; | ||
regLow = 0x00000000; | ||
int msb; // Most significant bit of reg (before shift) | ||
// Loop for each bit in high byte of reg | ||
for (int i=0; i < 8; i++) { | ||
// Save the most significant bit for later | ||
msb = regHigh & 0x80000000; | ||
// Shift reg left one bit | ||
regHigh <<= 1; | ||
if ((regLow & 0x80000000) != 0) { | ||
regHigh |= 0x00000001; | ||
} | ||
regLow <<= 1; | ||
// If most significant bit was 1 (before the shift) | ||
if (msb != 0) { | ||
// XOR the generator into reg | ||
regHigh ^= generatorHigh; | ||
regLow ^= generatorLow; | ||
} | ||
} | ||
} | ||
*/ | ||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/edu/cmu/sv/arinc838/crc/Crc16GeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Map; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class Crc16GeneratorTest { | ||
@Test | ||
public void calculateCrcTest() throws Exception { | ||
Map<BigInteger, byte[]> expectedCrcs = CrcGeneratorTestCommon | ||
.getExpectedCrcs("crc16"); | ||
for (BigInteger expectedCrc : expectedCrcs.keySet()) { | ||
long crc = Crc16Generator.calculateCrc(expectedCrcs | ||
.get(expectedCrc)); | ||
assertEquals(crc, expectedCrc.longValue()); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/edu/cmu/sv/arinc838/crc/Crc32GeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Map; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class Crc32GeneratorTest { | ||
@Test | ||
public void calculateCrcTest() throws Exception { | ||
Map<BigInteger, byte[]> expectedCrcs = CrcGeneratorTestCommon | ||
.getExpectedCrcs("crc32"); | ||
for (BigInteger expectedCrc : expectedCrcs.keySet()) { | ||
long crc = Crc32Generator.calculateCrc(expectedCrcs | ||
.get(expectedCrc)); | ||
assertEquals(crc, expectedCrc.longValue()); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/edu/cmu/sv/arinc838/crc/Crc64GeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.cmu.sv.arinc838.crc; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Map; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class Crc64GeneratorTest { | ||
@Test | ||
public void calculateCrcTest() throws Exception { | ||
Map<BigInteger, byte[]> expectedCrcs = CrcGeneratorTestCommon | ||
.getExpectedCrcs("crc64"); | ||
for (BigInteger expectedCrc : expectedCrcs.keySet()) { | ||
long crc = Crc64Generator.calculateCrc(expectedCrcs | ||
.get(expectedCrc)); | ||
assertEquals(crc, expectedCrc.longValue()); | ||
} | ||
} | ||
} |
Oops, something went wrong.