EmbDev.net

Forum: FPGA, VHDL & Verilog check lsb in vhdl


von basma (Guest)


Rate this post
useful
not useful
hi all;
i want to detect if the lsb is odd or even for integer data . how can i 
do it in vhdl code

von Marius S. (lupin)


Rate this post
useful
not useful
You can use the "mod" operator.

http://www.csee.umbc.edu/portal/help/VHDL/operator.html
1
if (myinteger mod 2 = 1) then
2
  -- odd
3
else
4
  -- even
5
end if;

Alternatively you can first convert to unsigned type and then check the 
lowest bit.
1
myunsigned <= to_unsigned(myinteger, length);
2
if (myunsigned(0) = '1') then
3
 -- odd
4
else
5
 -- even
6
end if;

: Edited by User
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.