Arindam Das Arindam Das - 1 year ago 134 Question

How do I split a 16-bit value into two 8-bit values in VB.NET?

I have a 16-bit value like this:


I want to split this in two 8-bit values like:

00000000 and 00000011

The 16-bit value is a variable,
, which is a unsigned 16-bit integer.

How can I do this in VB.NET?

Answer Source

You can use the BitConverter class:

Dim bytes As Byte() = BitConverter.GetBytes(byte_val1)

Now bytes(0) contains the lower byte (00000011) and bytes(1) contains the higher byte (00000000).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download