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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:26:02+00:00 2026-06-04T16:26:02+00:00

I am attempting to do the following in c: unsigned int mask; unsigned int

  • 0

I am attempting to do the following in c:

unsigned int mask;
unsigned int previous;
unsigned int new;
unsigned int out;

for( int i = 0; i < 8; ++i )
{
    bool bit_set = GET_BIT( mask, i );

    // If the mask bit is true, use the new bit, otherwise use the previous bit
    SET_BIT( out, i, GET_BIT( bit_set ? new : previous, i ) );
}

However I think there may be an easier and quicker way using bitwise operations. I have the truth table but I don’t know how to get the expression I need.

Truth table is:

m | p | n | o
0 | 0 | 0 | 0
1 | 0 | 0 | 0
0 | 1 | 0 | 1
1 | 1 | 0 | 0
0 | 0 | 1 | 0
1 | 0 | 1 | 1
0 | 1 | 1 | 1
1 | 1 | 1 | 1

How would I go about working this out?

  • 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-04T16:26:03+00:00Added an answer on June 4, 2026 at 4:26 pm

    Use Karnaugh Map – there is a solver available online. Pick “three values”, enter the expected results for all eight combinations, and use the expression the solver produces:

    F(m, p, n) = (p & !n) | (m & n)
    

    EDIT : You can expand this solution to do the whole byte at once, rather than doing it one bit at a time, by using the ~ bitwise NOT operator:

    result = (mask & new) | (~mask & previous);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error when attempting to use django-openid-auth OpenID discovery error: No
I'm a relatively new linux and rails dev and I'm attempting the following setup:
I am attempting to create the following code through the use of CodeDom: public
With the following statement (attempting to grant a role permissions to use a view),
The following code used to function without attempting to render a new template with
I am attempting to write the following character out in windows command prompt: ュ
I'm attempting to use the following code to serialize an anonymous type to JSON:
I am attempting to do the following List<JobPhase> jobPhases = new JobPhaseDao().findAll(); jobPhases.Remove(jobPhases.Where(m =>
When attempting to run the following assembly program: .globl start start: pushq $0x0 movq
I am attempting to run the following command in KornShell (ksh): set -A INDEXES

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.