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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:29:10+00:00 2026-05-16T02:29:10+00:00

Given a series of bits, what’s the best way to overwrite a particular range

  • 0

Given a series of bits, what’s the best way to overwrite a particular range of them.

For example, given:

0100 1010

Say I want to overwrite the middle 2 bits with 10 to make the result:

0101 0010

What would be the best way of doing this?

At first, I thought I would just shift the overwriting bits I want to the correct position (10000), and then use a bitwise OR. But I realized that while it preserves the other bits, there’s no way of specifying which bits I want to actually overwrite.

I was looking into Python’s bitarray module, but I just want to double-check that I’m not looking over an extremely simple bitwise operation to do this for me.

Thanks.

  • 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-16T02:29:11+00:00Added an answer on May 16, 2026 at 2:29 am

    This is done by first masking the bits you want to erase (forcing them to zero while preserving the other bits) before applying the bitwise OR.

    Use a bitwise AND with the pattern (in this case) 11100111.

    If you already have a “positive” version of the pattern (here this would be 00011000), which is easier to generate, you can obtain the “negative” version 11100111 using what is called 1’s complement, available as ~ in Python and most languages with a C-like syntax.

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

Sidebar

Related Questions

Given a connection object (or series of them), does anyone know of a way
Given time-series data, I want to find the best fitting logarithmic curve. What are
I want to create a program for generating the series for the given base-n.
Possible Duplicate: Generating a series of dates What is the best way in mysql
I need to check a given byte or series of bytes for a particular
I want to get the number of the reverse order of a given series
Given a series of objects, I am trying to split them up into a
Given a series x(i), i from 1 to N, let's say N = 10,000.
I need to build a full number range set given a series of numbers.
Given a dataframe column which is a series of integers (age), I want to

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.