Created
June 20, 2015 12:02
-
-
Save stoft/ae1e1dce95d96f3a1772 to your computer and use it in GitHub Desktop.
bitstring/byte play
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = for i <- 1..4, do: <<255>> | |
my_int = :crypto.bytes_to_integer(:erlang.list_to_binary list) | |
iex> Enum.reduce(1..255, [], fn(x, acc) -> [x|acc] end) |> IO.iodata_to_binary |> byte_size | |
255 | |
iex(7)> :crypto.bytes_to_integer(:erlang.list_to_binary list) | |
16777215 | |
iex(96)> <<a::1, rest::bitstring>> = :erlang.integer_to_binary 0b00000001 | |
"1" | |
iex(97)> a | |
0 | |
iex(98)> rest | |
<<49::size(7)>> | |
iex> :crypto.bytes_to_integer(<<255,255,255,255>>) |> Integer.to_string(2) | |
"11111111111111111111111111111111" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment