-2

I have a string that was placed into an array and turned into binary using .pack('B*'). How do I convert that binary data back into a string? .unpack('H*') is not the solution here, it returns a string of gibberish.

3
  • stackoverflow.com/questions/515478/… . I think this answers your question. Commented May 30, 2015 at 13:55
  • unpack('H*') is not the solution here, it returns a string of gibberish. Commented May 30, 2015 at 14:22
  • @bf86 I have added the answer please check. Commented May 30, 2015 at 16:31

1 Answer 1

0

I have tried this in my Rails Console and got the following. I hope this will help you.

a = "Hello".unpack("B*")

## Output
["0100100001100101011011000110110001101111"]

a.pack("B*")

## Output
"Hello"

a = "Hello".unpack("H*")

## Output
["48656c6c6f"]

a.pack("H*")

## Output
"Hello"
Sign up to request clarification or add additional context in comments.

Comments

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.