Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding odd-length strings #11

Open
rhinton opened this issue Nov 27, 2021 · 2 comments
Open

Decoding odd-length strings #11

rhinton opened this issue Nov 27, 2021 · 2 comments

Comments

@rhinton
Copy link

rhinton commented Nov 27, 2021

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;
@umarcor
Copy link

umarcor commented Nov 29, 2021

LGTM! @rhinton, do you want to propose a PR?

/cc @Paebbels @LarsAsplund

@Paebbels
Copy link
Owner

I would like to see the the init value of str_i being moved into the variable declaration to keep the function body clean.


@rhinton are you a user of this library?
Do you use it in synthesis or simulation (or because of VUnit?)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants