79294950

Date: 2024-12-19 16:25:39
Score: 1
Natty:
Report link

It happens because Convert.ToString(value, 2) does not include leading zeros. For a fixed-width 16-bit binary representation, you may use PadLeft(16, "0"c).

For example:

    Dim StAuto() As Integer = {&H3FFF}
    Dim StAuto_Int(0) As UInt16
    StAuto_Int(0) = Integer.Parse(StAuto(0))
    Dim s As String = Convert.ToString(StAuto_Int(0), 2).PadLeft(16, "0"c)
    TextBox1.Text = StAuto_Int(0)
    TextBox2.Text = $"{s} #of bits: {s.Length}"

enter image description here

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Xavier Junqué