3 ms·
I can never remember how modulus works, I use it so infrequently.
by traverseda 3y ago
I can never remember how modulus works, I use it so infrequently.
- deleted 3y ago[deleted]
- whoomp12342 3y agohighly recommend learning how division works within assembly. If you can understand sending this data into registers, you will never forget how mod works. Honestly, I dont even care if you use modulus or not. Solve the problem within a function demonstrating you know CS101 concepts we are good. like, really. No judgement, this is just an idiot filter.
- arghnoname 3y agoSure, but you probably remember division. "I can't remember of n % 2 returns 0 or 1 on even, so in place of that I wrote (if ((n/2)* 2 == n) for even, assuming integral division"
- AbsoluteCabbage 3y agoJust use n & 1 then. An odd number ends in binary 1; and’ing it with 1 yields 1 if its odd.
- emodendroket 3y agoYou don't even have to get that cute. Do integer division, multiply the result by the divisor, and subtract the product from the original dividend. Surely you can't say you don't use multiplication, division, and subtraction.
- emodendroket 3y agoI think implementing a function that does what a modulo operator would is itself a fairly straightforward question.
- d0mine 3y agoWhich kind? For example, can you name a difference between Python and C semantics for % op (if any).