473,413 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

What is equivalen converting C -> C#

Hi there,

I'm not very good at c and I was wondering if anyone could give
me a hand converting the following code snippet to c# ...

BYTE checksum(BYTE *InStr, BYTE len)
{

BYTE i, sum = 0;

for (i = 0; i < len; ++i) {

sum += InStr[i];

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return (sum);

}
Thanks a million !!!
Nov 16 '05 #1
4 1655
mdb
Just change 'BYTE' to 'byte', 'BYTE*' to byte[], remove 'BYTE len' from
the function declaration, and change 'len' to InStr.Length. Everything
else stays the same.

-mdb

ci****@insero-technologies.com (Ciaran) wrote in
news:f4*************************@posting.google.co m:
Hi there,

I'm not very good at c and I was wondering if anyone could give
me a hand converting the following code snippet to c# ...

BYTE checksum(BYTE *InStr, BYTE len)
{

BYTE i, sum = 0;

for (i = 0; i < len; ++i) {

sum += InStr[i];

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return (sum);

}
Thanks a million !!!


Nov 16 '05 #2
mdb
Just change 'BYTE' to 'byte', 'BYTE*' to byte[], remove 'BYTE len' from
the function declaration, and change 'len' to InStr.Length. Everything
else stays the same.

-mdb

ci****@insero-technologies.com (Ciaran) wrote in
news:f4*************************@posting.google.co m:
Hi there,

I'm not very good at c and I was wondering if anyone could give
me a hand converting the following code snippet to c# ...

BYTE checksum(BYTE *InStr, BYTE len)
{

BYTE i, sum = 0;

for (i = 0; i < len; ++i) {

sum += InStr[i];

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return (sum);

}
Thanks a million !!!


Nov 16 '05 #3
I did not cut and paste this into VS... caveat...

Byte checksum(Byte[] InStr)
{
Uint sum = 0;
for (Int ct = 0; ct < InStr.Length; ct++)
{
sum += InStr[ct];
if (sum > 0x7F)
{
sum = sum & 0x7F;
sum++;
}
}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return ((Byte)sum);

}


}

"Ciaran" <ci****@insero-technologies.com> wrote in message
news:f4*************************@posting.google.co m...
Hi there,

I'm not very good at c and I was wondering if anyone could give
me a hand converting the following code snippet to c# ...

BYTE checksum(BYTE *InStr, BYTE len)
{

BYTE i, sum = 0;

for (i = 0; i < len; ++i) {

sum += InStr[i];

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return (sum);

}
Thanks a million !!!

Nov 16 '05 #4
I did not cut and paste this into VS... caveat...

Byte checksum(Byte[] InStr)
{
Uint sum = 0;
for (Int ct = 0; ct < InStr.Length; ct++)
{
sum += InStr[ct];
if (sum > 0x7F)
{
sum = sum & 0x7F;
sum++;
}
}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return ((Byte)sum);

}


}

"Ciaran" <ci****@insero-technologies.com> wrote in message
news:f4*************************@posting.google.co m...
Hi there,

I'm not very good at c and I was wondering if anyone could give
me a hand converting the following code snippet to c# ...

BYTE checksum(BYTE *InStr, BYTE len)
{

BYTE i, sum = 0;

for (i = 0; i < len; ++i) {

sum += InStr[i];

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}
sum = ~sum;
sum &= 0x7F;

if (sum == 0)
sum = 0x7F;

return (sum);

}
Thanks a million !!!

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leader | last post by:
HI, i got a problem while using StrConv function in sql server. My requirement is:- suppose in a name field i have "jhon smith" Now i want to run a sql which will give me the result like "Jhon...
1
by: DickChristoph | last post by:
Hi I am interested in converting a Access 97 application to VB.Net (well okay rewriting). This would be a VB.Net client with a SQL Server backend, as opposed to my other alternative which would...
8
by: prabha | last post by:
Hello Everybody, I have to conert the word doc to multiple html files,according to the templates in the word doc. I had converted the word to xml.Also through Exsl ,had finished the multiple...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
by: Mary | last post by:
Hi, Does anyone know of any software out there that would convert an application written in VBScript to either VB.NET or C#/C++ quite quickly for me, or will I have to re-write the application...
2
by: Map Reader | last post by:
Greetings, I am converting an old VB6 application to use .NET. One of the old controls loads icons from the disk and displays them. However, the transparent color turns to blue somewhere in the...
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
16
by: manmit.walia | last post by:
Hello All, I have tried multiple online tools to convert an VB6 (bas) file to VB.NET file and no luck. I was hoping that someone could help me covert this. I am new to the .NET world and still...
10
by: minterman | last post by:
1. the program needs to convert btu to jules 2. Convert calories to joules 3. Convert joules to joules 4 exit the program. if the user type anything other than 1-4 the program should print a...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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
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 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.