Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20705 Discussions

mod - remainder confiusion

Altera_Forum
Honored Contributor II
982 Views

Dear all, 

 

Anyone can explain what mean by this line of code:  

ad<=(-5) mod 8; 

 

 

I know the "mod" is the remainder. But, why need negative? What the different with ad<=5 mod 8? Thanks in advance
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
294 Views

While I am not sure if this is the helpful or not (as I can not see the context of your code): 

 

5 as a byte: 

0b00000101 

 

-5 as a byte (one's complement): 

0b11111010 

 

-5 as a byte (two's complement): 

0b11111011
0 Kudos
Altera_Forum
Honored Contributor II
294 Views

Do some simple maths... 

If you divide 13 by 8 you get 1 remander 5. 

If you divide 13-8 (= 5) by 8 you get 0 remainder 5. 

If you divide 13-8*2 (= -3) by 8 you get -1 remainder 5 (or 0 remainder -3). 

If you divide 13-8*3 (= -11) by 8 you get -2 remainder 5 (or -1 remainder -3). 

Which of the quotient and remainder is negative varies according to the definition used by the language.
0 Kudos
Altera_Forum
Honored Contributor II
294 Views

 

--- Quote Start ---  

Do some simple maths... 

If you divide 13 by 8 you get 1 remander 5. 

If you divide 13-8 (= 5) by 8 you get 0 remainder 5. 

If you divide 13-8*2 (= -3) by 8 you get -1 remainder 5 (or 0 remainder -3). 

If you divide 13-8*3 (= -11) by 8 you get -2 remainder 5 (or -1 remainder -3). 

Which of the quotient and remainder is negative varies according to the definition used by the language. 

--- Quote End ---  

 

 

Hai all, 

 

Actually I try to understand this code example. I used this code as my reference to rewrite my own code later. One more thing, I try to view the state machine diagram using Quartus, but it said that "no state machine". I search from this forum, it said that I need to add reset case to create the state machine automatically. How to add the reset case? Thanks for quick reply
0 Kudos
Reply