EmbDev.net

Forum: FPGA, VHDL & Verilog check lsb in vhdl


Author: basma (Guest)
Posted on:

Rate this post
-1 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

Author: Marius S. (lupin)
Posted on:

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

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

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

: Edited by User

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.