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

  • Home
  • SEARCH
  • 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 6870183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:39:07+00:00 2026-05-27T03:39:07+00:00

Given an unsigned int A (32 bit), and another unsigned int B, where B’s

  • 0

Given an unsigned int A (32 bit), and another unsigned int B, where B’s binary form denotes the 10 “least reliable” bits of A, what is the fastest way to expand all 1024 potential values of A? I’m looking to do this in C.

E.g uint B is guaranteed to always have 10 1’s and 22 0’s in it’s binary form (10 least reliable bits).

For example, let’s say

A = 2323409845  
B = 1145324694

Their binary representations are:

a=10001010011111000110101110110101

b=01000100010001000100010010010110

B denotes the 10 least reliable bits of A. So each bit that is set to 1 in B denotes an unreliable bit in A.

I would like to calculate all 1024 possible values created by toggling any of those 10 bits in A.

  • 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-27T03:39:08+00:00Added an answer on May 27, 2026 at 3:39 am

    You can iterate through the 1024 different settings of the bits in b like so:

    unsigned long b = 1145324694;
    unsigned long c;
    
    c = 0;
    do {
        printf("%#.8lx\n", c & b);
        c = (c | ~b) + 1;
    } while (c);
    

    To use these to modify a you can just use XOR:

    unsigned long a = 2323409845;
    unsigned long b = 1145324694;
    unsigned long c;
    
    c = 0;
    do {
        printf("%#.8lx\n", a ^ (c & b));
        c = (c | ~b) + 1;
    } while (c);
    

    This method has the advantages that you don’t need to precalculate any tables, and you don’t need to hardcode the 1024 – it will loop based entirely on the number of 1 bits in b.

    It’s also a relatively simple matter to parallelise this algorithm using integer vector instructions.

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

Sidebar

Related Questions

Given: unsigned int a, b, c, d; I want: d = a * b
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
You are given a 32-bit unsigned integer array with length up to 2 32
Given the following piece of (pseudo-C++) code: float x=100, a=0.1; unsigned int height =
Given an unsigned int, I have to implement the following operations : Count the
What's a fast way to round up an unsigned int to a multiple of
I have this buffer given: unsigned char *buffer; int buffer_length; This is how I
Given an array, unsigned char q[32]=1100111... , how can I generate a 4-bytes bit-set,

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.