anchor.diff:  -export([pp/2]).
   
   %--- Types ---------------------------------------------------------------------
  +
   -type coding() :: bin | binary | dec | decimal | hex | hexadecimal
                     | nib | nibble.
   
  
positive.code: %  ok
  % '''
  -spec pp(binary()) -> 'ok'.
  pp(Bin) -> pp(Bin, #{display => hex}).
  
  % @doc Print binary as numbers.
  %
  
negative.code: -spec pp(binary(), coding() | #{display := coding()}) -> 'ok'.
  pp(Bin, Display) when is_atom(Display) ->
      pp(Bin, #{display => Display});
  pp(Bin, Opts) ->
      print_bitstring(Bin, normalize_opts(maps:merge(#{display => hex}, Opts))).
  
  %--- Internal ------------------------------------------------------------------
  
  normalize_opts(Opts) -> maps:map(fun normalize_opt/2, Opts).
  
  normalize_opt(display, hexadecimal) -> hex;
  normalize_opt(display, binary) -> bin;
  normalize_opt(display, nibble) -> nib;
  normalize_opt(display, decimal) -> dec;
  normalize_opt(display, hex) -> hex;
  normalize_opt(display, bin) -> bin;
  normalize_opt(display, nib) -> nib;
  normalize_opt(display, dec) -> dec;
  normalize_opt(display, Other) -> error({invalid_option, display, Other});
  normalize_opt(_Opt, Value) -> Value.
  
  print_bitstring(<<B:8/bitstring, Rest/bitstring>>, Opts) ->
      print_bits(B, Opts),
      io:format(" "),
      print_bitstring(Rest, Opts);
  print_bitstring(<<Rest/bitstring>>, Opts) ->
      print_bits(Rest, Opts),
      io:format("~n").
  
  print_bits(Bits, Opts) ->
      Size = bit_size(Bits),
      print_bits(Size, Bits, Opts).
  
  print_bits(Size, Bits, #{display := hex}) ->
      <<Int:Size>> = Bits,
      io:format("~*.16.0B", [Size div 4, Int]);
  print_bits(Size, Bits, #{display := bin}) ->
      <<Int:Size>> = Bits,
      io:format("~*.2.0B", [Size, Int]);
  print_bits(_Size, <<N1:4, N2:4>>, #{display := nib}) ->
      io:format("~4.2.0B ~4.2.0B ", [N1, N2]);
  print_bits(_Size, <<Byte>>, #{display := dec}) ->
      io:format("~3.10.0B", [Byte]);
  print_bits(0, <<>>, _Opts) ->
      ok;
  print_bits(_Size, _Byte, _Opts) ->
      io:format("foo").
  