# Convert string to binary value?

Hi,
I have looked in the language reference at Bin, but that only seems to convert an integer to binary.
Could someone point me in the right direction as to how I convert a simple string into it’s binary equivalent?

I haven’t tried this, but converting it first to an interger (CLong) and then to binary (a string representation using Bin) should work, shouldn’t it?:

``BinString=Bin(CLong(myNumber))``

Julen

Do you mean convert a binary string back to a number value?

If so:

```Dim n As Double Dim binaryString As String = "1111" n = Val("&b" + binaryString) //returns 15```

Ok, I understood you needed to convert an integer contained in a string to its binary form, not get the value of a binary number expressed in a string.

Paul,
I meant type in “hello world” into a text field, and have the binary (01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100) appear in a second text field

That function is in my M_String module.

``````//
// Example 1:
//
Public Function AscStr2BinStr( ByVal strString As String) As String
Dim intLoop As Integer
Dim strBinary As String
Dim intOneChar As Integer
Dim strOneBinChar As String
strBinary = ""
For intLoop = 1 to Len( strString )
intOneChar = Asc (Mid ( strString, intLoop, 1))
strOneBinChar = Bin( intOneChar )
If Len( strOneBinChar) < 8 Then
strOneBinChar = Mid( "00000000", 1, 8 - Len(strOneBinChar )) + strOneBinChar
End If
strBinary = strBinary + strOneBinChar + " "
Next
Return Trim( strBinary )
End Function``````

Thank you both !