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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:08+00:00 2026-05-26T23:14:08+00:00

How to exchange bits of given integer number {p, p+1, …, p+k-1} with {q,

  • 0

How to exchange bits of given integer number {p, p+1, ..., p+k-1} with {q, q+1, ..., q+k-1} in case where we have an overlap of both bits intervals;
p and q are bit’s positions:
p != q; k > 1.

Example:

p = 5;
q = 8;
k = 6;
16-bits decimal number 30 000 in binary representation:
01110101 00110000
================before exchange============
     101 001
  110101
================after exchange==============
     110 101
  101001
============================================

How to decide for bit’s positions 8, 9 and 10, which bits to put – 110 or 001?

  • 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-26T23:14:09+00:00Added an answer on May 26, 2026 at 11:14 pm

    The algorithm, if allowing overlaps, must be a lossy one.

    From your example:

    01110101 00110000
         |     |
         101 001
      |    |
      110101
    

    If you swap them, the values are:

    01110101 00110000
         |     |
         110 101
         *** - Mismatch!
      |    |
      101001
         *** - Mismatch!
    

    No matter what, if you allow an overlap, you cannot guarantee you can get the same original values out after doing the swap.

    Two ways to deal with this problem:

    • Document that your function is lossy, and that you cannot guarantee that you will be able to extract the swapped bits back out.
      I don’t like this idea, because I don’t know what I’d use such an algorithm for
    • Throw an exception if an overlap is fed into the algorithm, and write your program that uses this algorithm in such a way that it doesn’t generate overlaps.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Exchange server with lots of mountpoints. Given the path to the
I have an Exchange 2007 configured with ActiveSync and RPC over HTTP. Here are
I have an exchange rate table. I need to get current rate and previous
I have an Exchange account with multiple calendars defined. Is it possible to query
I have Exchange 2010 and I need to run a process using web services
Using Exchange Managed ApI, I need to get all appointments that have a created
We have Exchange integration into our CRM (diaries and email); we have done this
Is there a method of accessing an Exchange server that does not have IMAP
We have a problem deleting Appointments from Exchange using EWS. We try to delete
From everything I've seen on Stack Exchange and elsewhere, I have everything set up

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.