Library code snippets
ASCII to Binary string
This demonstrates how to convert an ASCII integer (ie an integer returned by Chr(#)) to its binary string.
Public Function cBIN(ByVal iC As Integer) As String
Dim X As Long, Y As Long, bC As Byte
cBIN = ""
X = 256
For Y = 1 To 8
bC = 0
X = X / 2
If iC >= X Then
bC = 1
iC = iC - X
End If
cBIN = cBIN & bC
Next Y
End Function
Call this function by doing a simple...
strBinary = cBIN(MyInteger)
Alternatively, you can use the following.
Private Function DecToBin(ByVal dIn As Double) As String
DecToBin = ""
While dIn >= 1
DecToBin = IIf(dIn Mod 2 = 0, "0", "1") & DecToBin
dIn = dIn \ 2
Wend
End Function
Private Function BinToDec(ByVal sIn As String) As Double
Dim x As Integer
BinToDec = 0
For x = 1 To Len(sIn)
BinToDec = BinToDec + (CInt(Mid(sIn, x, 1)) * (2 ^ (Len(sIn) - x)))
Next x
End Function
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Simple...
Just run the code but save the character values to corresponding array elements instead.
/the code
Dim i as long, MyArray() As Integer
Redim MyArray(Len(TheString)-1) As Integer
For i = 1 to len(TheString)
MyArray(i-1) = Asc(Mid(TheString,i,1))
Next i
/end code
Now it's an array of integers.
but the inverse process:
from a string to obtain a Array of integers(ASCII Codes for each caracter)?
This thread is for discussions of ASCII to Binary string.