VHDL mod operator

C

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" <cbr_929rr@hotmail.com> wrote in message
news:1160578125.838236.305800@e3g2000cwe.googlegroups.com...
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-
 
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" <cbr_929rr@hotmail.com> wrote in message
news:1160578125.838236.305800@e3g2000cwe.googlegroups.com...
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-
 
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" <cbr_929rr@hotmail.com> wrote in message
news:1160578125.838236.305800@e3g2000cwe.googlegroups.com...
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-
 
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" <cbr_929rr@hotmail.com> wrote in message
news:1160578125.838236.305800@e3g2000cwe.googlegroups.com...
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-
 

Welcome to EDABoard.com

Sponsor

Back
Top