janriemer,

Did you know that for natural numbers:

{x: >= 0, y = 2ⁿ}

the follow holds true:

x mod y

is equal to

x & (y - 1)

Example:

31882511 mod 1024

is equal to

31882511 & 1023

(where mod is the modulo operation and & is bitwise-and)

spacemagick,
@spacemagick@mastodon.social avatar

@janriemer
Since 2ⁿ-1 is just a string of ones
x & (y - 1)
is a null operation, right?

janriemer,

@spacemagick Indeed! Well deduced! 👍 🙂

janriemer,

@spacemagick ...but it's not really a null operation, but rather a "truncating" operation, once x > (y-1)

e.g. bits will look like this:

100000000 & 11111111 = 0 🙂

  • All
  • Subscribed
  • Moderated
  • Favorites
  • math
  • rosin
  • Youngstown
  • khanakhh
  • ngwrru68w68
  • slotface
  • ethstaker
  • mdbf
  • everett
  • kavyap
  • DreamBathrooms
  • thenastyranch
  • cisconetworking
  • magazineikmin
  • Durango
  • megavids
  • GTA5RPClips
  • Leos
  • tester
  • tacticalgear
  • InstantRegret
  • normalnudes
  • osvaldo12
  • cubers
  • anitta
  • modclub
  • provamag3
  • JUstTest
  • lostlight
  • All magazines