Skip to content

Decoding odd-length strings #11

@rhinton

Description

@rhinton

Function base16_decode in Encodings.pkg.vhdl fails on odd-length strings. Suggested correction:

  function base16_decode(constant str: string) return string is
    variable result: string (1 to (str'length + 1) / 2);
    variable str_i : string(1 to 2 * result'length);
  begin
    str_i := (others => ' ');
    str_i(1 to str'length) := str;
    for x in result'range loop
      result(x) := character'val(to_integer(
        to_unsigned(from_hex_string(
          str_i(2 * x - 1 to 2 * x),
          7, 0
        ), 8)
      ));
    end loop;
    return result;
  end function;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions