mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Binary Representation Of A String as an elixir til
This commit is contained in:
15
elixir/binary-representation-of-a-string.md
Normal file
15
elixir/binary-representation-of-a-string.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Binary Representation Of A String
|
||||
|
||||
> A common trick in Elixir is to concatenate the null byte <<0>> to a string
|
||||
> to see its inner binary representation.
|
||||
|
||||
A couple example of this can be seen in the following snippet of code:
|
||||
|
||||
```elixir
|
||||
> "hello" <> <<0>>
|
||||
<<104, 101, 108, 108, 111, 0>>
|
||||
> "ƒå®øü†" <> <<0>>
|
||||
<<198, 146, 195, 165, 194, 174, 195, 184, 195, 188, 226, 128, 160, 0>>
|
||||
```
|
||||
|
||||
[source](http://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html)
|
||||
Reference in New Issue
Block a user