CodeConverter
CodeConverter copied to clipboard
C# -> VB: decimal/double instead of int, byte instead of integer
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/
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!