locked
Conversion from C# to VB.Net query RRS feed

  • Question

  • Hi,

    I am trying to convert a C# script into VB.Net and for the most part I have been successful. However there are a couple of lines I just cannot figure out since I very rarely work with bitwise operations or hexidecimal values.

    Could anyone tell me the VB.Net equivalent of the following:

    expandedBytes[pos++] = (byte)IntToHex((b >> 4) & 0xf);
                    expandedBytes[pos++] = (byte)IntToHex(b & 0x0f);
    

    Many thanks!


    Thanks, Cep
    Sunday, December 11, 2011 1:30 PM

Answers

  • You can use an on-line C# to VB convertor, for example I used www.developerfusion.com/tools/convert/csharp-to-vb/ to get

    expandedBytes(System.Math.Max(System.Threading.Interlocked.Increment(pos),pos - 1)) = CByte(IntToHex((b >> 4) And &Hf))
    expandedBytes(System.Math.Max(System.Threading.Interlocked.Increment(pos),pos - 1)) = CByte(IntToHex(b And &Hf))
    The ++ operator doesn't have a direct equivalent in VB.

    HTH,

    Andrew


    • Edited by Andrew Morton Sunday, December 11, 2011 2:03 PM typo
    • Marked as answer by Cepeleon Monday, December 12, 2011 2:45 PM
    Sunday, December 11, 2011 2:02 PM
  • expandedBytes(pos) = CByte(IntToHex((b >> 4) And &Hf))
    pos += 1
    expandedBytes(pos) = CByte(IntToHex(b And &Hf))
    pos += 1
    


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Proposed as answer by Andrew Morton Sunday, December 11, 2011 4:42 PM
    • Marked as answer by Cepeleon Monday, December 12, 2011 2:45 PM
    Sunday, December 11, 2011 3:45 PM

All replies

  • Hi,

     expandedBytes(pos++) = CType(IntToHex((b>4 & 0xf), Byte)

     expandedBytes(pos++) = CType(IntToHex((b & 0xf), Byte)

    By

     A Pathfinder..

    JoSwa


    Sunday, December 11, 2011 1:46 PM
  • You can use an on-line C# to VB convertor, for example I used www.developerfusion.com/tools/convert/csharp-to-vb/ to get

    expandedBytes(System.Math.Max(System.Threading.Interlocked.Increment(pos),pos - 1)) = CByte(IntToHex((b >> 4) And &Hf))
    expandedBytes(System.Math.Max(System.Threading.Interlocked.Increment(pos),pos - 1)) = CByte(IntToHex(b And &Hf))
    The ++ operator doesn't have a direct equivalent in VB.

    HTH,

    Andrew


    • Edited by Andrew Morton Sunday, December 11, 2011 2:03 PM typo
    • Marked as answer by Cepeleon Monday, December 12, 2011 2:45 PM
    Sunday, December 11, 2011 2:02 PM
  • expandedBytes(pos) = CByte(IntToHex((b >> 4) And &Hf))
    pos += 1
    expandedBytes(pos) = CByte(IntToHex(b And &Hf))
    pos += 1
    


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Proposed as answer by Andrew Morton Sunday, December 11, 2011 4:42 PM
    • Marked as answer by Cepeleon Monday, December 12, 2011 2:45 PM
    Sunday, December 11, 2011 3:45 PM
  • Thanks for the assist guys, in fact it turns out that your answers need a slight tweak since VS2010 does not appear to like it:

     

                    expandedBytes(pos) = CByte(AscW(IntToHex((b >> 4) And &HF)))
                    pos += 1
                    expandedBytes(pos) = CByte(AscW(IntToHex((b And &HF))))<br/>pos += 1
    



    Thanks, Cep
    Monday, December 12, 2011 2:48 PM