Dim a As Integer, i As Integer, b(20) As Integer, c As Integer, d As Integer

        i = 0
        a = TextBox1.Text
        While a > 1
            b(i) = a Mod 2
            a = a / 2
            i = i + 1
        End While
        
  b(i) = a

        While i >= 0
            c = c & b(i)
            i = i - 1
        End While
        Label5.Text = c
        Label5.Visible = True

hey guys i wrote the above prog to convert decimal to binary the result i get is wrong for the last digit..


eg when converting 100 i get 10100100 instead of 1100100

thanks in advance..

Recommended Answers

All 2 Replies

HI

Use \ operator instead of / operator, because / operator in vb gives floating result and \ operator gives integer result. so floating value will be rounded to integer.

For example

Dim a as Integer

   a = 3 / 2      
   MsgBox a     ' Gives 2

   a = 3 \ 2
   MsgBox a     ' Gives 1

3 / 2 gives 1.5 and it will be converted to 2

thanks you prob solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.