-
August 25th, 2011, 06:04 PM
#1
Help Me Convert Some Code
Hello,
I have a routine that is currently in c++ and I really need to have it converted to c sharp. Could someone with a lot more knowledge then myself have a look at the code and help me out.
The code follows:
Thanks
Mike
This is the c++ code.
Code:
char * computeChecksum(char* message)
{
static char ascii_checksum[ 5 ];
WORD checksum = 0
int i = 0;
while ( message[i] != '\0';
{
checksum += (unsigned) message[i];
i++ ;
}
checksum = -(checksum & 0xFFFF);
sprintf( ascii_checksum, "%4.4X, checksum );
return ascii_checksum;
}
-
September 7th, 2011, 08:06 PM
#2
Re: Help Me Convert Some Code
string computeChecksum(string m)
{
char[] message=m.ToCharArray();
static char ascii_checksum[ 5 ];
int checksum = 0
int i = 0;
while ( message[i] != '\0';
{
checksum += (int) message[i];
i++ ;
}
checksum = -(checksum & 0xFFFF);
string ascii_checksum= checksum.ToString() ;
return ascii_checksum;
}
i guess this would help you
-
September 8th, 2011, 05:19 PM
#3
Re: Help Me Convert Some Code
Your C++ code was not compilable - after correcting it and converting I get:
Code:
private string computeChecksum_ascii_checksum = new string(new char[5]);
private string[] computeChecksum(sbyte[] message)
{
//C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
// static sbyte ascii_checksum[5];
ushort checksum = 0;
int i = 0;
while (message[i] != '\0')
{
checksum += (uint) message[i];
i++;
}
checksum = -(checksum & 0xFFFF);
computeChecksum_ascii_checksum = string.Format("{0,4:X4}", checksum);
return computeChecksum_ascii_checksum;
}
Last edited by David Anton; September 8th, 2011 at 05:53 PM.
-
September 8th, 2011, 08:16 PM
#4
Re: Help Me Convert Some Code
Originally Posted by David Anton
Your C++ code was not compilable - after correcting it and converting I get:
Code:
private string computeChecksum_ascii_checksum = new string(new char[5]);
private string[] computeChecksum(sbyte[] message)
{
//C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
// static sbyte ascii_checksum[5];
ushort checksum = 0;
int i = 0;
while (message[i] != '\0')
{
checksum += (uint) message[i];
i++;
}
checksum = -(checksum & 0xFFFF);
computeChecksum_ascii_checksum = string.Format("{0,4:X4}", checksum);
return computeChecksum_ascii_checksum;
}
Method should return String not String[]
-
September 9th, 2011, 12:27 AM
#5
Re: Help Me Convert Some Code
Right you are (this is fixed in the next build).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|