簡體   English   中英

將std_logic_vector解析為整數

[英]Parsing std_logic_vector to integer

如果我將兩個std_logic_vector分別轉換為值1和0

signal mlx, mtx : std_logic_vector(15 downto 0) 

通過整數

variable WLX : integer;
variable WTX : integer;

WLX := TO_INTEGER(signed(mlx));
WTX := TO_INTEGER(signed(mtx));

然后將這些減法與-1文字進行比較:

if WTX-WLX = -1 

結果會是真的嗎?

謝謝

如果mlx = X“0001”且mtx = X“0000”,那么是的,從mtx中減去mlx作為整數得到-1,所以給出問題答案是肯定的。

但是:將值轉換為整數以便對它們進行操作或比較它們通常是代碼寫得不好的標志。

你為什么不使用signed for mlx和mtx,並避免使用整數?

architecture arch of ent is
    signal mlx, mtx : signed(15 downto 0);
begin
    process(clk) begin
        if(rising_edge(clk)) then
            if(mtx - mlx = -1) then
                -- Do what needs to be done.
            end if;
        end if;
    end process;
end architecture;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM