Skip to content

Instantly share code, notes, and snippets.

@refactor
Last active May 24, 2023 16:40
Show Gist options
  • Select an option

  • Save refactor/750d7f4de4179879b7611216a5c997a6 to your computer and use it in GitHub Desktop.

Select an option

Save refactor/750d7f4de4179879b7611216a5c997a6 to your computer and use it in GitHub Desktop.

Revisions

  1. refactor revised this gist May 24, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions erlang format for hex
    Original file line number Diff line number Diff line change
    @@ -17,3 +17,7 @@

    > HV = crypto:hash(sha3_512, Bin).
    > << <<(binary:list_to_bin(io_lib:format("~2.16.0b", [X])))/binary>> || <<X>> <= HV>>.
    > H = binary:encode_hex(HV, lowercase).
    > HV == binary:decode_hex(H).
    true

  2. refactor revised this gist May 24, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion erlang format for hex
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    > io_lib:format("~2.16.0B", [15]).
    0F


    > io_lib:format("~2.16.#b", [15]).
    "#f"

    @@ -13,5 +12,8 @@
    > io_lib:format("~8.2.0b", [3]).
    "00000011"

    > io_lib:format("~8.2.*b", [$*, 3]).
    "******11"

    > HV = crypto:hash(sha3_512, Bin).
    > << <<(binary:list_to_bin(io_lib:format("~2.16.0b", [X])))/binary>> || <<X>> <= HV>>.
  3. refactor created this gist May 24, 2023.
    17 changes: 17 additions & 0 deletions erlang format for hex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    > io_lib:format("~2.16.0B", [15]).
    0F


    > io_lib:format("~2.16.#b", [15]).
    "#f"

    > io_lib:format("~2.2.#b", [1]).
    "#1"
    > io_lib:format("~2.2.#b", [2]).
    "10"

    > io_lib:format("~8.2.0b", [3]).
    "00000011"

    > HV = crypto:hash(sha3_512, Bin).
    > << <<(binary:list_to_bin(io_lib:format("~2.16.0b", [X])))/binary>> || <<X>> <= HV>>.