What is equivalen converting C -> C#

  • Thread starter Thread starter Ciaran
  • Start date Start date
C

Ciaran

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;

if (sum & 0x80) {

sum &= 0x7F;

++sum;

}

}


sum = ~sum;
sum &= 0x7F;

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

return (sum);

}


Thanks a million !!!
 
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

(e-mail address removed) (Ciaran) wrote in
 
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);

}




}
 
Back
Top