# VHDL mod operator

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

1. ### cbr_929rrGuest

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

2. ### Ben JonesGuest

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

3. ### cbr_929rrGuest

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_929rrGuest

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, Oct 11, 2006
5. ### AndyGuest

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

Andy, Oct 11, 2006
6. ### Mehdi1149

Joined:
May 9, 2013
Messages:
1
0
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