473,513 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CRC 16 implementation in c#

1 New Member
Hi

Can someone tell me if the c# implementation of a 16 bit crc code is correct.

A 128 bit message pointer is passed into the crc function to add 16 crc bits to the message.

The messsage generation function is:
Expand|Select|Wrap|Line Numbers
  1. void gen01dat( int data_len, int* out_array )
  2. {
  3.    randomize();
  4.    // generate the random data and write it to the output array
  5.  
  6.    for(int t=0; t<data_len-16; t++)
  7.       *(out_array+t)=(int) (rand()/(RAND_MAX/2)>0.5);
  8. }
  9.  
  10. The crc calculation is:
  11.  
  12. //crc calculation function is 
  13. void crc(int lenght,int* msg_array)
  14. {
  15.  
  16.    for(int i=lenght-16; i<lenght; i++)
  17.       msg_array[i]=0;
  18.  
  19.    int remainder[17];
  20.    int crc_gen[17]={1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ,0 ,1};
  21.  
  22.    for(int i=0; i<17; i++)
  23.    remainder[i]=0;
  24.  
  25.    for(int i=0; i<lenght; i++)
  26.    {
  27.       for(int j=0; j<16; j++)
  28.       remainder[16-j]=remainder[15-j];
  29.  
  30.       remainder[0]= msg_array[i];
  31.  
  32.       if(remainder[16]==1)
  33.       {
  34.          for(int j=0; j<17; j++)
  35.          remainder[j] ^= crc_gen[j];
  36.       }
  37.  
  38.    }
  39.  
  40.    for(int i=lenght-16; i<lenght; i++)
  41.    {
  42.      msg_array[i]=remainder[-i+lenght-1];
  43.    }
  44. }
  45.  
  46.  
  47. // the main function would read
  48. int main(int argc, char* argv[])   //command line project
  49. {
  50.  
  51. int msg_lenght=128;
  52.  
  53. int* data_n1=new int [msg_lenght];
  54.  
  55. gen01dat(msg_lenght,data_n1);
  56. crc(msg_lenght,data_n1);
  57.  
  58. delete [] data_n1;
  59.  
  60. getchar(); 
  61. return 0;
  62.  
  63. }
Sep 2 '07 #1
3 6820
sicarie
4,677 Recognized Expert Moderator Specialist
Moving over to .NET Forum (just after I check to make sure there isn't a double-post in there) where our C# Experts will probably be able to help you better than I am...
Nov 1 '07 #2
r035198x
13,262 MVP
I assume by crc you mean Cyclic Redundancy Check? Well did you actually try out the code with known values to see if it works?
What happens to the function if a value less than 16 is passed to it as the length (which you were writting lenght)?
Nov 1 '07 #3
thegeneralguy
10 New Member
Since you are using pointers and pointer referencing (it looks like C++) you will need to explicitly tell the compiler to allow unsafe code. You will also need to declare the functions unsafe.
Nov 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1797
by: jenniferyiu | last post by:
IMHO, simply NO. False actually, practically.
9
4617
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
29
2218
by: Enrico `Trippo' Porreca | last post by:
Both K&R book and Steve Summit's tutorial define a getline() function correctly testing the return value of getchar() against EOF. I know that getchar() returns EOF or the character value cast to...
52
3696
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
20
6045
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
7
2048
by: desktop | last post by:
I the C++ standard page 472 it says that an associative container can be constructed like X(i,j,c) where i and j are input iterators to elements. But in the implementation there is no constructor...
6
3934
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
1980
by: anto.anish | last post by:
Hi , Since, i did not want to write instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template...
1
2763
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of...
173
13766
by: Ron Ford | last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use MS's Visual C++ Express and use its C capability. In the past with my MS products, I've simply needed to make .c the...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.