Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15920

VS 2017 [RESOLVED] Trying to understand unknown operations in C# to convert to VB

$
0
0
Hello,

I have the following function from a C# project that I'm trying to convert to VB code :
Code:

private const string Hex = "0123456789abcdef";
public static string DecodeHex(string input)
        {
            var stringBuilder = new StringBuilder();
            var i = 0;
            do
            {
                var a = ((Hex.IndexOf(input[i++]) << 4) & 0xf0);
                var b = 0;

                if (i < input.Length)
                    b = (Hex.IndexOf(input[i++]) & 0xf);

                stringBuilder.Append(new[] { (char)(a | b) });
            } while (i < input.Length);

            return stringBuilder.ToString();
        }

I tried to write this in my VB project :
Code:

Private Const Hex As String = "0123456789abcdef"
Public Function DecodeHex(ByVal input As String) As String
        Dim stringBuilder = New StringBuilder()
        Dim i = 0

        Do
            Dim a = (Hex.IndexOf(input(i)) << 4 & CByte(&HF0))
            Dim b = 0
            i += 1

            If i < input.Length Then
                b = (Hex.IndexOf(input(i)) & CByte(&HF))
                i += 1
            End If

            'stringBuilder.Append({CChar((a Or b))})
            stringBuilder.Append({(a Or b)})

        Loop While i < input.Length

        Return stringBuilder.ToString()
    End Function

No values are corresponding between C# and my VB attempt.

I don't even know what variable "a" and "b" are, is it Byte? Integer?
I also don't understand what happen on" stringBuilder.Append(a Or b)". Is stringBuilder choose randomly to append between a or b?

I'm running short on time and it seems I have a lot of work to learn what happen here.
I would be grateful if someone could explain to me what is going on in this function!
Thanks

Viewing all articles
Browse latest Browse all 15920

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>