Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

Representing only a set of bits in a binary number

Hello,

I need a clarification regarding this topic. I have a binary number, say "00000011111111100......" and I need to write a VHDL code such that it calculates the number of 0s and 1s for a single sequence. What I mean by a single sequence is that after all the 1's are checked and calculated, the operation or the checking should be terminated. For instance, in our example we have 9 1's and once the next bit is checked, obviously we have zero as the next bit. So, we need to stop the operation of checking and the process should be terminated. Can anyone help me to solve this issue. Thanks in advance.

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Is there any way to exit an if statement without using a loop in VHDL

    --- Quote End ---

    No. If you are trying to do this, then you have a misunderstanding of VHDL (and other programming langauges)

    The if statements are meant to represent decisions at a given moment in time. why would you exit an if statement?

    Your code would also no work on real hardware. I highly suggest going back to your text book and tutorials on digital logic design.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks, for the motivation. I found out my mistakes and the code is working pretty well