Forum: FPGA, VHDL & Verilog check lsb in vhdl

von basma (Guest)

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

von Marius S. (lupin)

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

if (myinteger mod 2 = 1) then
  -- odd
  -- 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
 -- even
end if;

: Edited by User


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.