VHDL mod operator

Discussion in 'VHDL' started by cbr_929rr, Oct 11, 2006.

  1. cbr_929rr

    cbr_929rr Guest

    I just don't seem to understand how the modulo operator works even
    after going over info online and a couple of books with examples.

    Could someone please what this operator does and explain how this works
    with clear examples?

    cbr_929rr, Oct 11, 2006
    1. Advertisements

  2. cbr_929rr

    Ben Jones Guest

    What's not to understand?

    "a mod b" means "the remainder when a is divided by b".

    So 15 mod 10 = 5, 17 mod 8 = 1, etc.


    Note that unless 'b' is a power of 2 or both a and b are constants, the mod
    operation is most likely not synthesizable.

    Ben Jones, Oct 11, 2006
    1. Advertisements

  3. cbr_929rr

    cbr_929rr Guest

    In VHDL, I thought that the mod operator is different from the REM, the
    remainder operation.

    An example I saw online
    7 mod (-4) = -1

    The theory was that A mod B = A - (B*N) for some integer N
    What does that really mean?
    cbr_929rr, Oct 11, 2006
  4. cbr_929rr

    cbr_929rr Guest

    I just learnt that the behavior is same for REM and MOD when the sign
    on both sides of the MOD operator are same (A mod B = A REM B when and
    B have the same signs as one another).
    However, for MOD the result would get the sign of B and for REM, the
    result would get the sign of A when the signs of A and B are different.

    The question is how would you calculate the result in the following

    -5 mod 3 = 1
    7 mod -4 = -1

    It would be helpful if someone explains the result in steps.

    cbr_929rr, Oct 11, 2006
  5. cbr_929rr

    Andy Guest

    I believe the sign of MOD follows the sign of the 2nd operand. The sign
    of REM follows the sign of the first operand.

    Andy, Oct 11, 2006
  6. cbr_929rr


    May 9, 2013
    Likes Received:
    My Maths teacher told me-

    A(mod)B = C

    Means C is the reminder
    13 (mod) 7 = 6
    15 (mod) 2 = 1

    A = B (mod) C means, C divides A-B
    13 = 7 (mod) 6 means 6 divides 13-7
    And 1 divides 15 - 2

    But later I found it fails on 16 (mod) 7 = 2
    For 2 doesn't divides 16-7...

    Hence still I am in confusion... Please anyone tell me the 2nd part in details..
    Mehdi1149, May 9, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.