VHDL constant initialisation
I am just studying some VHDL code and for the initialisation of a constant it says the 开发者_Python百科following:
constant address: integer := 16#8E#;
I have never seen this kind of definition before. Does anybody know how this translates to an ordinary number in decimal?
Thanks!
To expand further (if you have the VHDL LRM, you can read the gory details in section 13.4.2) you can put any base (between 2 and 16 inclusive) before the first #
and an exponent after the second #
. You can also put _
s in to separate sets of numbers.
The exponent is always expressed in base 10 and cannot be negative. Example (the VHDL highlighting leaves a little to be desired!)
entity test_numbers is
end entity test_numbers;
architecture a1 of test_numbers is
begin
process is
begin -- process
report integer'image(16#FF#); -- 255
report integer'image(10#1_000#); -- 1000
report integer'image(10#1#e3); -- 1000 another way
report integer'image(2#1#e10); -- 1024
report integer'image(4#100#); -- 16
wait;
end process;
end architecture a1;
reports:
# Loading work.test_numbers(a1)
# ** Note: 255
# Time: 0 ns Iteration: 0 Instance: /test_numbers
# ** Note: 1000
# Time: 0 ns Iteration: 0 Instance: /test_numbers
# ** Note: 1000
# Time: 0 ns Iteration: 0 Instance: /test_numbers
# ** Note: 1024
# Time: 0 ns Iteration: 0 Instance: /test_numbers
# ** Note: 16
# Time: 0 ns Iteration: 0 Instance: /test_numbers
16#8E#
means 8E
in base 16 (ie hexidecimal). For binary, you could write 2#10001110#
for the same number. Once you know this, getting the decimal version should be easy.
精彩评论