Getting confused

Mark82

Newcomer
Joined
Jun 22, 2003
Messages
12
I know this is asking a bit of a favour. but this is part of a function that I am trying to Import over from VB.net to C# but I am stuck I have the rest of the function working but I can not get this figured out.
Can someone please explain how I can do this.
The main parts i'm having trouble with are.

The Ascii conversion in: lngbcc = lngbcc + Asc(Mid(ReadingString, lngN, 1))

and the conversion to HEX in the last line.

I have figured out the SubString parts to replace the Mid function.
and the for loop is no problem.

Any Help would be great thanks.


Visual Basic:
Dim lngbcc As Long
        Dim lngN As Long
        Dim YY As String
        lngbcc = 0
        For lngN = 2 To Len(ReadingString)
            lngbcc = lngbcc + Asc(Mid(ReadingString, lngN, 1))
            lngbcc = lngbcc And 255
        Next lngN
        YY = Hex(lngbcc)
 
Last edited:
try this:

Code:
string str = "this is a test... testing... 1..2..3..";
string HexString = "";

byte[] textBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
foreach(byte b in textBytes)
{
	HexString += String.Format("{0:X2}",b);
}

Console.WriteLine(HexString);

Hope this helps!

Andreas
 
Thanks that has helped a lot. But It leaves me with a very large result about 9 digits long, The original post i made only leaves me with 2 digits. I have changed the code to include my string, rather than the Test string. but to no avail.

Thanks
 
Back
Top