Public Function IsGoodStringToBit(Optional sSuffix As String) As Boolean
' verify correct StringToBit returns
' returns True if all tests are passed
'
' We gotta deal with the ANSI/ASCII vs Unicode issue here:
' StringToBit has *3 sub-disciplines* in analogy with the Asc-function:
'   1. StringToBit:    8 bits per char, unicode is converted to ANSIASCII
'   2. StringToBitB:   8 bits per char, first unicode byte (the upper unicode byte is ignored)
'   3. StringToBitW:  16 bits per char, both unicode bytes
' For example: the Euro-sign "€" = unicode 8364 (&H20AC), ANSIASCII-code 128
'   StringToBit("€")  --> "10000000"          '=  128 =   &H80 =  Asc("€")
'   StringToBitB("€") --> "10101100"          '=  172 =   &HAC = AscB("€")
'   StringToBitW("€") --> "0010000010101100"  '= 8364 = &H20AC = AscW("€")
'
  On Error GoTo hell
  
  Dim fFailed As Boolean
  Dim i As Long
    
  ' 1. replace "StringToBit..." with the name of your function to test
  ' 2. set sSuffix param to "", "B", or "W" (see notes above)
  Select Case UCase$(sSuffix)
  Case ""
    For i = 0 To 255
      If StringToBit05(Chr$(i)) <> ByteToBit01((i)) Then
        Debug.Print i; StringToBit05(Chr$(i)); " <> "; ByteToBit01((i))
        Stop: fFailed = True
      End If
    Next
    If StringToBit05("€ÿ") <> "1000000011111111" Then Stop: fFailed = True
  
  Case "B"
    For i = 0 To 255
      If StringToBitB05(Chr$(i)) <> ByteToBit01(AscB(Chr$(i))) Then
        Debug.Print i; StringToBitB05(Chr$(i)); " <> "; ByteToBit01(AscB(Chr$(i)))
        Stop: fFailed = True
      End If
    Next
    If StringToBitB05("€ÿ") <> "1010110011111111" Then Stop: fFailed = True
  
  Case "W"
    For i = 0 To 255
      If StringToBitW05(Chr$(i)) <> Right$(LongToBit01(AscW(Chr$(i))), 16) Then
        Debug.Print i; StringToBitW05(Chr$(i)); " <> "; Right$(LongToBit01(AscW(Chr$(i))), 16)
        Stop: fFailed = True
      End If
    Next
    If StringToBitW05("€ÿ") <> "00100000101011000000000011111111" Then Stop: fFailed = True
  
  End Select
      
  
  ' well done
  IsGoodStringToBit = Not fFailed
  
  Exit Function
hell:
  MsgBox "ERROR at Chr$(" & i & "), that's " & Chr$(i), vbCritical
End Function


Back to StringToBit
Back to StringToBitB
Back to StringToBitW