Forum Discussion
Altera_Forum
Honored Contributor
13 years agomod - remainder confiusion
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 advance3 Replies
- Altera_Forum
Honored Contributor
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 - Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
--- 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