This will be pretty fast. I'm sure it can be optimized further:
Private Function BinToStr(bin As String) As String
Dim i As Long, Count As Long
Dim strCompare(1) As String
Dim b() As Byte
ReDim b(0 To Len(bin) / 8 - 1)
Debug.Assert Len(bin) Mod 8 = 0
Dim strNibble As String
strNibble = "0000-0001-0010-0011-0100-
"1000-1001-1010-1011-1100-
For i = 1 To Len(bin) - 7 Step 8
strCompare(0) = Mid$(bin, i, 4)
strCompare(1) = Mid$(bin, i + 4, 4)
b(Count) = (InStr(1, strNibble, strCompare(0) & "-") - 1) / 5 * 16 + (InStr(1, strNibble, strCompare(1) & "-") - 1) / 5
Count = Count + 1
Next i
BinToStr = StrConv(b, vbUnicode)
End Function
Main Topics
Browse All Topics





by: aikimarkPosted on 2005-03-14 at 08:40:11ID: 13536389
There are a few things to address. Here's an overview of performance enhancements:
1. minimize operations
2. use the most efficient operators
3. take advantage of as many 'tricks' as possible
4. take advantage of VB language features
5. consider Windows APIs as alternatives to VB functions/statements
=========================
Before I show code examples I need to know if the string length is guaranteed to be a multiple of 8 or if the leading zero characters ("0") might have been removed.