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: -
void gen01dat( int data_len, int* out_array )
-
{
-
randomize();
-
// generate the random data and write it to the output array
-
-
for(int t=0; t<data_len-16; t++)
-
*(out_array+t)=(int) (rand()/(RAND_MAX/2)>0.5);
-
}
-
-
The crc calculation is:
-
-
//crc calculation function is
-
void crc(int lenght,int* msg_array)
-
{
-
-
for(int i=lenght-16; i<lenght; i++)
-
msg_array[i]=0;
-
-
int remainder[17];
-
int crc_gen[17]={1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ,0 ,1};
-
-
for(int i=0; i<17; i++)
-
remainder[i]=0;
-
-
for(int i=0; i<lenght; i++)
-
{
-
for(int j=0; j<16; j++)
-
remainder[16-j]=remainder[15-j];
-
-
remainder[0]= msg_array[i];
-
-
if(remainder[16]==1)
-
{
-
for(int j=0; j<17; j++)
-
remainder[j] ^= crc_gen[j];
-
}
-
-
}
-
-
for(int i=lenght-16; i<lenght; i++)
-
{
-
msg_array[i]=remainder[-i+lenght-1];
-
}
-
}
-
-
-
// the main function would read
-
int main(int argc, char* argv[]) //command line project
-
{
-
-
int msg_lenght=128;
-
-
int* data_n1=new int [msg_lenght];
-
-
gen01dat(msg_lenght,data_n1);
-
crc(msg_lenght,data_n1);
-
-
delete [] data_n1;
-
-
getchar();
-
return 0;
-
-
}
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...
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)?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jenniferyiu |
last post by:
IMHO, simply NO.
False actually, practically.
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |