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 8423199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:39:42+00:00 2026-06-10T03:39:42+00:00

I have a number on which I perform a specific operation I want to

  • 0

I have a number on which I perform a specific operation
I want to make sure that the number is still divisible after the operation.

Let’s say I have an integer x which is divisible by PAGE_S

does this produces an integer which is also divisible by PAGE_S ?

x^ ~(PAGE_S-1);

so (x % PAGE_S) == ( (x^ ~(PAGE_S-1)) % PAGE_S) ?
As far as I tested, it works, but I need to understand why…

p.s this is part of a code of translating virtual memory addresses to physical addresses

  • 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-06-10T03:39:44+00:00Added an answer on June 10, 2026 at 3:39 am

    Yes, but only if PAGE_S is a power of two.

    If PAGE_S is a power of two (say, 2k), then its binary representation is a 1 followed by k 0s. So, PAGE_S-1 will be k 1s in binary, so ~(PAGE_S-1) is all 1s followed by k 0s.

    The xor operation (^) will flip any bits of the first operand for which the corresponding bit in the second operand is 1; for example, 101101 ^ 111000 is 010101 because the first three bits are flipped.

    Since x is divisible by PAGE_S, the last k bits must be zero. Since the last k bits of ~(PAGE_S-1) are also zero, the last k bits of x^~(PAGE_S-1) are zero so it is divisible by PAGE_S. This also inverts all the other bits of x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several number inputs of varying lengths which I want to style such
In my application I have a number of objects which can perform some long
I have a number of xml documents from which I want to retrieve all
I have a number of input button elements throughout my site that perform Ajax
I have a Maven project which performs a number of time consuming tests as
I have a JavaScript function which is quite long and performs a number of
I have a number which is in this form : 2012-01 (2012 as current
I have a number of strings which contain words which are bunched together and
I have a number of links which I would like to get some information
I have create an array containing person firstname,lastname and number which i populate in

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.