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?

    Thanks
     
    cbr_929rr, Oct 11, 2006
    #1
    1. Advertisements

  2. cbr_929rr

    Ben Jones Guest

    "cbr_929rr" <> wrote in message
    news:...
    >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.


    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.

    http://en.wikipedia.org/wiki/Modular_arithmetic

    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-
     
    Ben Jones, Oct 11, 2006
    #2
    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?


    Ben Jones wrote:
    > "cbr_929rr" <> wrote in message
    > news:...
    > >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.

    >
    > 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.
    >
    > http://en.wikipedia.org/wiki/Modular_arithmetic
    >
    > 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-
     
    cbr_929rr, Oct 11, 2006
    #3
  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
    cases?

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


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

    Thanks.


    cbr_929rr wrote:
    > 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?
    >
    >
    > Ben Jones wrote:
    > > "cbr_929rr" <> wrote in message
    > > news:...
    > > >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.

    > >
    > > 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.
    > >
    > > http://en.wikipedia.org/wiki/Modular_arithmetic
    > >
    > > 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-
     
    cbr_929rr, Oct 11, 2006
    #4
  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


    cbr_929rr wrote:
    > 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
    > cases?
    >
    > -5 mod 3 = 1
    > 7 mod -4 = -1
    >
    >
    > It would be helpful if someone explains the result in steps.
    >
    > Thanks.
    >
    >
    > cbr_929rr wrote:
    > > 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?
    > >
    > >
    > > Ben Jones wrote:
    > > > "cbr_929rr" <> wrote in message
    > > > news:...
    > > > >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.
    > > >
    > > > 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.
    > > >
    > > > http://en.wikipedia.org/wiki/Modular_arithmetic
    > > >
    > > > 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-
     
    Andy, Oct 11, 2006
    #5
  6. cbr_929rr

    Mehdi1149

    Joined:
    May 9, 2013
    Messages:
    1
    My Maths teacher told me-

    A(mod)B = C

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

    &
    A = B (mod) C means, C divides A-B
    (e.g)
    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
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kwaj

    Mod (%) Function in VHDL

    Kwaj, Jan 14, 2004, in forum: VHDL
    Replies:
    7
    Views:
    45,659
    jacky Renaux
    Jan 20, 2004
  2. Basel Naamna

    MOD operator synthesis

    Basel Naamna, May 8, 2004, in forum: VHDL
    Replies:
    2
    Views:
    3,897
    Ken Smith
    May 10, 2004
  3. Hari Sekhon
    Replies:
    0
    Views:
    617
    Hari Sekhon
    Jun 20, 2006
  4. ryles
    Replies:
    3
    Views:
    616
    Piet van Oostrum
    Jul 26, 2009
  5. T. Onoma
    Replies:
    9
    Views:
    425
    Dave Thomas
    Dec 15, 2003
Loading...

Share This Page