Iβm not sure that the OP has solved his problem since then, but in connection with his remark that his binary is utf16-le : I found out that itβs the fastest for this encoding (and for those who are more experienced with Elixir probably Enum.reduce ) way - use Enum.reduce :
# coercing it into utf8 gives us ["D", <<0>>, "e", <<0>>, "v", <<0>>, "a", <<0>>, "s", <<0>>, "t", <<0>>, "a", <<0>>, "t", <<0>>, "o", <<0>>, "r", <<0>>] <<68, 0, 101, 0, 118, 0, 97, 0, 115, 0, 116, 0, 97, 0, 116, 0, 111, 0, 114, 0>> |> String.codepoints() |> Enum.reduce("", fn(codepoint, result) -> << parsed :: 8>> = codepoint if parsed == 0, do: result, else: result <> <<parsed>> end) # "Devastator" |> IO.puts()
Assumptions:
Since I am still studying elixir, it took me a while to find this solution. I looked at other libraries created by people, even using something like iconv at the bash level.