#!/usr/bin/env elixir # Test different encoding approaches for length 224 length = 224 IO.puts("=== Encoding length #{length} ===") # Option 1: Binary encoding (what hex should produce) binary_bytes = <> IO.puts("Binary encoding: #{Base.encode16(binary_bytes, case: :upper)} (bytes: #{inspect(binary_bytes)})") # Option 2: BCD encoding of decimal representation decimal_str = Integer.to_string(length) |> String.pad_leading(4, "0") # "0224" bcd_bytes = decimal_str |> String.to_charlist() |> Enum.chunk_every(2) |> Enum.map(fn [hi, lo] -> ((hi - ?0) <<< 4) ||| (lo - ?0) end) |> :binary.list_to_bin() IO.puts("BCD encoding of '#{decimal_str}': #{Base.encode16(bcd_bytes, case: :upper)} (bytes: #{inspect(bcd_bytes)})") # Option 3: ASCII hex string hex_str = Integer.to_string(length, 16) |> String.upcase() |> String.pad_leading(4, "0") # "00E0" IO.puts("ASCII hex string: #{hex_str} (bytes: #{inspect(hex_str)})") IO.puts("\n=== Your debug message showed ===") IO.puts("Hex encoded length 224 -> 00E0") IO.puts("This suggests you want: #{Base.encode16(binary_bytes, case: :upper)} as binary bytes")