VHDL mod operator

C

cbr_929rr

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
 
B

Ben Jones

cbr_929rr said:
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-
 
C

cbr_929rr

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?
 
C

cbr_929rr

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.
 
A

Andy

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
 
Joined
May 9, 2013
Messages
1
Reaction score
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..
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top