From f096ec090bb41ec71ba672ee4e62d51bddd72ab6 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 6 Aug 2016 11:48:17 -0500 Subject: [PATCH] Add Binary Representation Of A String as an elixir til --- README.md | 3 ++- elixir/binary-representation-of-a-string.md | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 elixir/binary-representation-of-a-string.md diff --git a/README.md b/README.md index a1e2979..cae19b7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_450 TILs and counting..._ +_451 TILs and counting..._ --- @@ -83,6 +83,7 @@ _450 TILs and counting..._ - [Append To A Keyword List](elixir/append-to-a-keyword-list.md) - [Assert An Exception Is Raised](elixir/assert-an-exception-is-raised.md) +- [Binary Representation Of A String](elixir/binary-representation-of-a-string.md) - [Create A Date With The Date Sigil](elixir/create-a-date-with-the-date-sigil.md) - [Dynamically Generating Atoms](elixir/dynamically-generating-atoms.md) - [Execute Raw SQL In An Ecto Migration](elixir/execute-raw-sql-in-an-ecto-migration.md) diff --git a/elixir/binary-representation-of-a-string.md b/elixir/binary-representation-of-a-string.md new file mode 100644 index 0000000..382f61c --- /dev/null +++ b/elixir/binary-representation-of-a-string.md @@ -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)