Dividing by 10 in digital logic (and modulo)

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 13368 Views - Last Post: 06 April 2012 - 07:11 AM

#16 elgose   User is offline

  • D.I.C Head

Reputation: 102
  • View blog
  • Posts: 228
  • Joined: 03-December 09

Re: Dividing by 10 in digital logic (and modulo)

Posted 06 April 2012 - 12:17 AM

Oh lord, reminds me recently someone at work was trying to get clever with using bit-masks and doing some semi-complicated bitwise operations that were just atrocious. There was a bug (after a couple hours we gave up) but along the way I came across if statements like:
if ((maskA &= maskB) == 0) //<-- accidental assignment of maskA rather than just &'ing
    maskA |= maskB; //<-- obviously, this is just maskA = maskB, not what he intended at all


But who knows, maybe the ultimate problem would have come from realizing the shift operator had a bug? :dead:
Was This Post Helpful? 0
  • +
  • -

#17 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12350
  • View blog
  • Posts: 20,984
  • Joined: 19-March 11

Re: Dividing by 10 in digital logic (and modulo)

Posted 06 April 2012 - 12:34 AM

Clearly the world would be a much better place if more people would realize that Java is a language that's designed to discourage cleverness of that type.
You usually don't need to pretend that Java is C, and it usually doesn't work out well when you do.
Was This Post Helpful? 0
  • +
  • -

#18 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 173
  • View blog
  • Posts: 1,115
  • Joined: 03-April 12

Re: Dividing by 10 in digital logic (and modulo)

Posted 06 April 2012 - 07:11 AM

Modulus is an algebraic structure consisting of a set and operations.
What I meant that the operations are such that the result doesn't get out of the set.

Say, set is numbers 0 - 9, then addition is defines such that 9 + 9 doesn't make up 18 that doesn't belong to the set, but it's "wrapped around" so that the result belongs to the set of numbers 0 - 9.

That means that also 1 - 9 doesn't make negative number.

Modulo is good for, say, ring buffer indexing whereas reminder is not - at least if "putback" is supported.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2