How to decode and print base64 with unprintable character

Hi, I have a encoded64 string that I want to decode and print as string, it should be human readable

iex(33)> {:ok, bb} = Base.decode64("g2gCbQAAAA5zaGFocnlhcnMtaU1hY20AAAAIYcJbhqjzRj4=")
 <<131, 104, 2, 109, 0, 0, 0, 14, 115, 104, 97, 104, 114, 121, 97, 114, 115, 45,
   105, 77, 97, 99, 109, 0, 0, 0, 8, 97, 194, 91, 134, 168, 243, 70, 62>>

Now how can convert bb to string?

Thank you.

Are you sure your decoded binary is a valid string? I try to print it using IO.puts and I get:

** (ArgumentError) errors were found at the given arguments:

  • 2nd argument: not valid character data (an iodata term)

That is my problem!!

It is something like this (based on


Now in elixir how can I decode and print to see?
if I get something like this it should convert to codeprint.
For example:
\u0000 is a null character

Garbage in, garbage out. You need to determine the source of the data, and find out what format it is stored in, in order to work out how to decode it.

1 Like

It’s not for sure that. It’s a best effort guess at what the source might be – replacing any unknown things with this fancy ? character. This often works ok for any single byte, possibly ascii, characters, because a lot of charsets match in the ascii characters range, but all bets are off for other characters / multi byte sequences.

1 Like