CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

C# -> VB: decimal/double instead of int, byte instead of integer

Open jamieS95 opened this issue 5 years ago • 1 comments

Input code

  private static int GetBit(byte[] h, int i)
        {
            return h[i / 8] >> (i % 8) & 1;
        }

Erroneous output

    Private Shared Function GetBit(ByVal h As Byte(), ByVal i As Integer) As Integer
        Return h(i / 8) >> i Mod 8 And 1
    End Function

Expected output

   Private Shared Function GetBit(ByVal h As Byte(), ByVal i As Integer) As Integer
 Return (CInt(h(i \ 8)) >> ((i Mod 8)) And 1)
end function

Details

  • https://converter.telerik.com/

jamieS95 avatar Aug 25 '20 14:08 jamieS95

I've updated the erroneous output to the output from the latest version (hosted at codeconverter.icsharpcode.net) I think there are 3 separate fixes needed:

  • Use Integer division where inputs are integers in c#
  • convert left and right of binary expressions to their expected type
  • add parentheses... Basically everywhere

Getting this particular case working should be reasonably straightforward, there are likely lots of related edge cases that are harder.

Thanks for the report!

GrahamTheCoder avatar Aug 29 '20 08:08 GrahamTheCoder