Title: SAS CRC algorithm C# .NET Post by: JonaMX on July 16, 2011, 05:21:17 PM Does anyone has the CRC SAS algorithm ??
I don't know how to implement in C# the one that includes IGT SAS 6.02 document (attached picture) :103- Title: Re: SAS CRC algorithm C# .NET Post by: zarobhr on July 16, 2011, 05:29:17 PM i hvae one that works in c#i will have to post itfrom the other pc
Title: Re: SAS CRC algorithm C# .NET Post by: JonaMX on July 16, 2011, 05:33:01 PM i hvae one that works in c#i will have to post itfrom the other pc thanks I'll waiting it Title: Re: SAS CRC algorithm C# .NET Post by: zarobhr on July 16, 2011, 05:40:26 PM here you go i use this to both compute the crc when sending commands and to compute the crc on recieved data to make sure the recieved crc is valid
in order for this to work the byte[] cannot include the crc bytes Code: public static byte[] ComputeCRC(byte[] val) Moderator: I enclosed your code in an SMS code block, because the command "c = val [ i ];" was interpreted by the forum software as an italic command. SF :31- Title: Re: SAS CRC algorithm C# .NET Post by: JonaMX on July 16, 2011, 05:47:22 PM here you go i use this to both compute the crc when sending commands and to compute the crc on recieved data to make sure the recieved crc is valid in order for this to work the byte[] cannot include the crc bytes public static byte[] ComputeCRC(byte[] val) { long crc; long q; byte c; crc = 0; for (int i = 0; i < val.Length; i++) { c = val; q = (crc ^ c) & 0x0f; crc = (crc >> 4) ^ (q * 0x1081); q = (crc ^ (c >> 4)) & 0xf; crc = (crc >> 4) ^ (q * 0x1081); } return new byte[] { (byte)(crc & 0xff),(byte)(crc >> 8) }; } Thanks zarobhr I'll use it and comeback to tell you how it works Title: Re: SAS CRC algorithm C# .NET Post by: JonaMX on July 16, 2011, 06:05:52 PM It works pretty well thanks again zarobhr :131- :3-
Title: Re: SAS CRC algorithm C# .NET Post by: StatFreak on July 16, 2011, 06:52:39 PM It works pretty well thanks again zarobhr :131- :3- Thanks for letting us know. :3- :259- I'm assuming that you found the little glitch in the code displayed in the post, which I just corrected. I noticed that your original code was using the value 17d, instead of 15d, which is equal to 0x0f. Stat :31- Title: Re: SAS CRC algorithm C# .NET Post by: zarobhr on July 16, 2011, 06:55:49 PM aw is that the icon that looks like a # sign
Title: Re: SAS CRC algorithm C# .NET Post by: StatFreak on July 16, 2011, 06:58:37 PM aw is that the icon that looks like a # sign Yes it is. As you can probably tell, it doesn't get much use around here. :72- :72- BTW, I gane you a :259- too. Title: Re: SAS CRC algorithm C# .NET Post by: zarobhr on July 16, 2011, 07:01:23 PM aw is that the icon that looks like a # sign Yes it is. As you can probably tell, it doesn't get much use around here. :72- :72- BTW, I gane you a :259- too. thanks Title: Re: SAS CRC algorithm C# .NET Post by: JonaMX on July 16, 2011, 07:29:59 PM It works pretty well thanks again zarobhr :131- :3- Thanks for letting us know. :3- :259- I'm assuming that you found the little glitch in the code displayed in the post, which I just corrected. I noticed that your original code was using the value 17d, instead of 15d, which is equal to 0x0f. Stat :31- Yeah in fact it is c=val[ i ]; Not c=val; :259- Title: Re: SAS CRC algorithm C# .NET Post by: StatFreak on July 16, 2011, 07:55:09 PM Well, you wouldn't have much of a recursive "For/While" loop if there were no "i". :209- :200- :97- :97- :97-
Title: Re: SAS CRC algorithm C# .NET Post by: stayouttadabunker on July 17, 2011, 01:26:57 AM I gave all you guys a + Karma! :131-
Great little thread! :89- |