When I try to convert integer value to binary 16 bit, it just showing 14 bit numbers. Do you have any solution for this?
This is my code:
StAuto_Int(0) = Integer.Parse(StAuto(0))
TextBox1.Text = StAuto_Int(0)
TextBox2.Text = Convert.ToString(StAuto_Int(0), 2)
Dimas prasetyo utomo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
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}"