Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:39:37+00:00 2026-05-15T10:39:37+00:00

We know that for example modulo of power of two can be expressed like

  • 0

We know that for example modulo of power of two can be expressed like this:

x % 2 inpower n == x & (2 inpower n - 1).

Examples:

x % 2 == x & 1
x % 4 == x & 3
x % 8 == x & 7

What about general nonpower of two numbers?

Let’s say:

x % 7 == ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:39:37+00:00Added an answer on May 15, 2026 at 10:39 am

    First of all, it’s actually not accurate to say that

    x % 2 == x & 1
    

    Simple counterexample: x = -1. In many languages, including Java, -1 % 2 == -1. That is, % is not necessarily the traditional mathematical definition of modulo. Java calls it the “remainder operator”, for example.

    With regards to bitwise optimization, only modulo powers of two can “easily” be done in bitwise arithmetics. Generally speaking, only modulo powers of base b can “easily” be done with base b representation of numbers.

    In base 10, for example, for non-negative N, N mod 10^k is just taking the least significant k digits.

    References

    • JLS 15.17.3 Remainder Operator %
    • Wikipedia/Modulo Operation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that: browsers can download two components in parallel per hostname example www.example.com
I know that jQuery, for example, can do animation of sorts. I also know
I know that javascript, for example supports functions inside of functions, like so: function
I know that you can't repeat match groups in Lua. For example, if I
I know that TextBlock can present a FlowDocument , for example: <TextBlock Name=txtFont> <Run
Example: before: text_before_specific_character(specific_character)text_to_be_deleted after: text_before_specific_character I know that it can be done with sed
Does somebody know a module, which has a function that returns ( for example
I know that variables in F# are immutable by default. But, for example in
The example below, is just an example, I know that I don't need an
I know from wikipedia for example that exception handling is used in an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.