Skip to content

Instantly share code, notes, and snippets.

@tony612
Created July 31, 2019 02:29
Show Gist options
  • Select an option

  • Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.

Select an option

Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.

Revisions

  1. tony612 created this gist Jul 31, 2019.
    21 changes: 21 additions & 0 deletions binary_parse_slow.exs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    defmodule BinaryParseSlow do
    def parse(bin) do
    parse(bin, 0)
    end

    def parse(bin, acc) do
    case do_parse(bin) do
    {:nofin, x, rest} ->
    parse(rest, acc + x)
    {:fin, x} ->
    acc + x
    end
    end

    def do_parse(<<0::1, x::7, _::bits>>) do
    {:fin, x}
    end
    def do_parse(<<1::1, x::7, rest::bits>>) do
    {:nofin, x, rest}
    end
    end