Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir, convert binary to byte array

Tags:

elixir

I have the following value in Elixir: <<140, 143, 153, 192, 237, 255, 10>> Binaries don't seem to be enumerable. I need to convert it to a list so I can iterate over it, byte-by-byte, something like: [140, 143, 153, 192, 237, 255, 10]. I understand that to_char_array would do it if all the bytes were valid unicode characters but they aren't.

Just getting started with Elixir and really appreciate any suggestions for converting binaries to lists(byte arrays).

like image 454
Bruce Avatar asked May 27 '16 14:05

Bruce


1 Answers

Have a look at erlang's bin_to_list/1

:binary.bin_to_list(<<140, 143, 153, 192, 237, 255, 10>>)
# [140, 143, 153, 192, 237, 255, 10]
like image 140
Sebastián Duque Avatar answered Oct 19 '22 20:10

Sebastián Duque