1

I'm trying to simulate an algoritham in cryptography and I need to convert a string of 0s and 1s back into a word. Example: I have: 01011110010101101000001101100001101 I have split it into an array of strings: 0101111, 0010101, ...

each member has 7 characters. I want to get a letter that 0101111 represents in UTF8? How do I do this?

I try CType("0010101", Byte), but it fails. I can pass max 111 this way. Help :/

3
  • Erm... shouldn't bytes be 8 bits instead of 7? Commented Jun 12, 2014 at 17:15
  • @DanielCook That might not work out so well. Every byte with an arbitrary 7-bit pattern (with a 0 msb) is a valid UTF-8 encoding with one byte per character. That's not true for arbitrary 8-bit patterns. One character set that would work for is CP437. Commented Jun 13, 2014 at 2:32
  • For what it's worth, with VB.NET and inefficient LINQ, I got zT␅6X. I didn't notice the [vba] until later. Commented Jun 13, 2014 at 2:47

1 Answer 1

1

UTF-8 is 8 bit, those are only 7 bits. Do you mean 7 bit ASCII?

In that case here you go:

Function BinToStr(binStr As String) As String

    Dim i As Long

    For i = 0 To (Len(binStr) / 7) - 1
        [A1] = CLng(Mid(binStr, i * 7 + 1, 7))
        BinToStr = BinToStr & Chr([BIN2DEC(A1)])
    Next
End Function

If that's not what you're looking for, let me know.

Sign up to request clarification or add additional context in comments.

2 Comments

What do the square brackets [ ] do ?
@ja72 That's built into Excel VBA as a quick way to access cell references and functions. He may not have even been asking for VBA, he may have meant VB.NET, in which case [A1] would just be replaced with a temporary variable and the BIN2DEC function would have to come from the VB.NET library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.