Hello friends,
I am facing an issue while coding.I want to convert integer into its binary equivalent using VBScript.
Can any one Fix this issue for me.
Thanks in Advance.
Printable View
Hello friends,
I am facing an issue while coding.I want to convert integer into its binary equivalent using VBScript.
Can any one Fix this issue for me.
Thanks in Advance.
Try to use this code i hope it will work for you.
HTML Code:Function IntToBin(ByVal IntegerNumber As Long)
IntNum = IntegerNumber
Do
TempValue = IntNum Mod 2
BinValue = CStr(TempValue) + BinValue
IntNum = IntNum \ 2
Loop Until IntNum = 0
IntToBin = BinValue
End Function
Function BinToInt(ByVal BinaryNumber As String)
Length = Len(BinaryNumber)
For x = 1 To Length
TempValue = TempValue + Val(Mid(BinaryNumber, Length - x + 1, 1)) * 2 ^ (x - 1)
Next
BinToInt = TempValue
End Function
Private Sub Command1_Click()
Text2.Text = IntToBin(Val(Text1.Text))
End Sub
Private Sub Command2_Click()
Text4.Text = BinToInt(Text3.Text)
End Sub
Use this is code
HTML Code:SUB IntToBin (byte%, bin$) 'Add STATIC here to get SUB to
bin$ = "" 'work in QuickBasic 3.00
temp% = byte%
FOR i = 0 TO 7
IF temp% AND 1 THEN
bin$ = "1" + bin$
ELSE
bin$ = "0" + bin$
END IF
temp% = temp% \ 2
NEXT
END SUB