0
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..

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by sunderthomas
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.