C# to VB transformation

O

OpticTygre

Hi,

Checking out some byte shifting code in C#, and interested in putting it
into VB.NET. Anyone know how to transform the following into VB?

public static void Put32Bit(long value, byte[]b, int offset)
{
b[0+offset] = (byte) ((value & 0xff000000) >> 24);
b[1+offset] = (byte) ((value & 0x00ff0000) >> 16);
b[2+offset] = (byte) ((value & 0x0000ff00) >> 8);
b[3+offset] = (byte) (value & 0x000000ff);
}

Thanks for any help.
 
T

Tom Shelton

Hi,

Checking out some byte shifting code in C#, and interested in putting it
into VB.NET. Anyone know how to transform the following into VB?

public static void Put32Bit(long value, byte[]b, int offset)
{
b[0+offset] = (byte) ((value & 0xff000000) >> 24);
b[1+offset] = (byte) ((value & 0x00ff0000) >> 16);
b[2+offset] = (byte) ((value & 0x0000ff00) >> 8);
b[3+offset] = (byte) (value & 0x000000ff);
}

Thanks for any help.
Hmmm... (untested :)

Public Shared Sub Put32Bit _
(value As Long, b() As Byte, offset As Integer)

b(0 + offset) = CType (((value & &HFF000000) >> 24), Byte)
b(1 + offset) = CType (((value & &H00FF0000) >> 16), Byte)
b(2 + offset) = CType (((value & &H0000FF00) >> 8), Byte)
b(3 + offset) = CType (((value & &H000000FF)), Byte)

End Sub
 
G

Guest

From our Instant VB C# to VB.NET converter:

Public Shared Sub Put32Bit(ByVal value As Long, ByVal b As Byte(), ByVal
offset As Integer)
b(0+offset) = CByte((value And &Hff000000) >> 24)
b(1+offset) = CByte((value And &H00ff0000) >> 16)
b(2+offset) = CByte((value And &H0000ff00) >> 8)
b(3+offset) = CByte(value And &H000000ff)
End Sub

Hope this helps,
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 
T

Tom Shelton

From our Instant VB C# to VB.NET converter:

Public Shared Sub Put32Bit(ByVal value As Long, ByVal b As Byte(), ByVal
offset As Integer)
b(0+offset) = CByte((value And &Hff000000) >> 24)
b(1+offset) = CByte((value And &H00ff0000) >> 16)
b(2+offset) = CByte((value And &H0000ff00) >> 8)
b(3+offset) = CByte(value And &H000000ff)
End Sub

Nuts! I for got to change the & to And...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top