1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elixir Comprehensions(内包表記) Bitstring generators

Last updated at Posted at 2014-10-14

Elixir Comprehensions(内包表記) Bitstring generators

概要

Elixir の Comprehensions(内包表記) Bitstring generators について。

サンプル

8bit × 4 の IP を扱います。

サンプルコード

ips=<<255,255,255,0,192,168,1,1,172,16,1,1>>
for <<first_octet::8, second_octet::8, third_octed::8, forth_octed::8 <- ips>>, do: IO.inspect {first_octet, second_octet, third_octed, forth_octed}
for <<first_octet::4, second_octet::4, third_octed::4, forth_octed::4 <- ips>>, do: IO.inspect {first_octet, second_octet, third_octed, forth_octed}
  • 出力
# 8bit単位
{255, 255, 255, 0}
{192, 168, 1, 1}
{172, 16, 1, 1}

# 4bit単位にした場合
{15, 15, 15, 15}
{15, 15, 0, 0}
{12, 0, 10, 8}
{0, 1, 0, 1}
{10, 12, 1, 0}
{0, 1, 0, 1}

参照

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?