Public Function Encode7Bit (ByVal Content As String) As String 'Prepare Dim CharArray As Char () = Content.ToCharArray Dim c As Char Dim t As String For Each c In CharArray t = CharTo7Bits (c) t Next' Add "0" DIM I as integer if (t.length mod 8) <> 0 THEN for i = 1 to 8 - (T.Length Mod 8) T = "0" T NEXT End End End AS SPLIT INTO 8BITS DIM Result AS STRING FOR I = T.LENGTH - 8 TO 0 Step -8 Result = Result BitStoHEX (MID (T, I 1, 8)) Next Return Result End Function
Private function bitsTohex (Byval Bits As String) AS String 'Convert 8bits To Hex String Dim I, V AS Integer for i = 0 to Bits.LENGTH - 1 V = V VAL (MID (BITS, I 1, 1)) * 2 ^ (7 - i) Next Dim Result AS String Result = Format (v, "x") if result.length = 1 Then Result = "0" Result End IF RETURN RESULT END FUNCTION
Private Function CharTo7Bits (BYVAL C As Char) AS STRING DIM RESULT AS STRING DIM I as Integer for i = 0 to 6 IF (ASC (c) and 2 ^ i)> 0 Then Result = "1" Result else result = " 0 " Result End If next Return Result End Function