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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:57:44+00:00 2026-05-25T13:57:44+00:00

I need to create three bit masks that end up in three 32-bit unsigned

  • 0

I need to create three bit masks that end up in three 32-bit unsigned ints (let’s call them x, y and z). The masks should end up like this:

x: 0000 0001 1111 1111 1111 1111 1111 1111
y: 0000 1110 0000 0000 0000 0000 0000 0000
z: 1111 0000 0000 0000 0000 0000 0000 0000

So far I’ve got this:

unsigned int x = (1<<25)-1;
unsigned int y = (~x)&((1<<28)-1);
unsigned int z = (~x)<<3;

But it seems a bit messy. Can anyone come up with a more concise (and readable) way?

  • 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-25T13:57:44+00:00Added an answer on May 25, 2026 at 1:57 pm

    If you are using C99, use the “new” fixed width types:

    uint32_t x, y, z;
    x = 0x01FFFFFF;
    y = 0x0E000000;
    z = 0xF0000000;
    

    Or you could use “ugly” octal 🙂

    x = 000177777777; // 00 000 001 111 111 111 111 111 111 111 111
    y = 001600000000; // 00 001 110 000 000 000 000 000 000 000 000
    z = 036000000000; // 11 110 000 000 000 000 000 000 000 000 000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to have a RegEx that will match a URI like this based
This may seem a bit odd, but I really need to create a workaround
Problem I need to create 32 Bit numbers (signed or unsigned doesn't matter, the
I need to create a bit of Javascript that can search inputted HTML from
In my constructor, I want to create a random color. Therefore, I need three
I need to create an XML schema that validates a tree structure of an
I need to create an application that decrypts data that is encrypted using AES
I need to create a connection with a table that isn't in my control
I need to create a toggle that animates upwards not downwards in other words

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.