
March 28th, 2012, 01:37 AM
|
|
|
Quote: | Originally Posted by joyride123 I know how to use during decimaltobinary and binarytodecimal function on vb 2010,but i cant figure out the way to output without using vb 2010 function
can anyone send me code on how to create a code for converting binary to decimal and decimal to binary without using vb function please. |
One must assume that you are talking whole numbers here. All numbers are stored in the computer as binary numbers, but each type of number (short integer, long integer, single precision, double precision etc) has it's own storage methodology. So assuming we are dealing with a 16 bit integer:
Private Sub cmdConvert_Click()
Dim N%
Dim Number As Long
Dim sBinary As String
Number = Val(Text1.Text)
sBinary = String(16, "0")
Do Until N% > 15
If Number And 2 ^ N% Then
Mid$(sBinary, 16 - N%, 1) = "1"
End If
N% = N% + 1
Loop
Text2.Text = sBinary
End Sub
The form would have 2 text boxes and 1 command button. Since most languages don't deal directly with binary numbers, we have to represent it as a binary string. Conversion back would just be the reverse.
|