Skip to content

Commit

Permalink
encodings: style
Browse files Browse the repository at this point in the history
  • Loading branch information
1138-4EB committed Nov 29, 2019
1 parent 51c6c2b commit 8c4d8fb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions vunit/vhdl/encodings/src/encodings_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

library ieee;
use ieee.fixed_pkg.from_hex_string;
use ieee.fixed_pkg.to_unsigned;
use ieee.fixed_pkg.to_hex_string;
use ieee.fixed_pkg.ufixed;
use ieee.fixed_pkg.to_integer;
use ieee.fixed_pkg.to_ufixed;
use ieee.numeric_std.to_integer;

use work.string_ops.lower;

Expand All @@ -25,23 +25,26 @@ package body encodings_pkg is
function b16decode(str: string) return string is
constant str_i : string(1 to str'length) := str;
variable result: string (1 to str'length / 2);
variable character_code : ufixed(7 downto 0);
begin
for x in result'range loop
character_code := from_hex_string(str_i(2 * x - 1 to 2 * x));
result(x) := character'val(to_integer(character_code));
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 b16encode(str: string) return string is
constant str_i : string(1 to str'length) := str;
variable result: string (1 to str'length * 2);
variable character_code : string(1 to 4);
begin
for x in str_i'range loop
character_code := to_hex_string(to_ufixed(character'pos(str_i(x)), 7, 0));
result(2 * x - 1 to 2 * x) := lower(character_code(1 to 2));
result(2 * x - 1 to 2 * x) := lower(to_hex_string(
to_ufixed(character'pos(str_i(x)), 7, 0)
)(1 to 2));
end loop;
return result;
end;
Expand Down

0 comments on commit 8c4d8fb

Please sign in to comment.