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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:10:02+00:00 2026-05-31T21:10:02+00:00

This may be a really silly question, but it just crossed my mind and

  • 0

This may be a really silly question, but it just crossed my mind and I thought it would be interesting to know for sure….

So here is the scenario:

Users have 3 options for each day of the week: AM, PM, and OFF. These are mutually exclusive choices, so there is no option to work both an AM and PM on same day.

So if I wanted to store their AM shifts and PM shifts as separate bitmasks, and User1 chooses the following:

 S    M   T   W   Th   F   Sa
 A    P   X   A   X    P   A

I would have the following:

 $shifts['User1']['AM'] = 73;  //  1001001
 $shifts['User1']['PM'] = 34;  //  0100010

Now, if I just wanted to know which days User1 worked, I could obviously just do:

 $shifts['User1']['All'] = $shifts['User1']['AM'] | $shifts['User1']['PM'];

Or even just:

 $shifts['User1']['All'] = $shifts['User1']['AM'] + $shifts['User1']['PM'];

But what if I wanted the final result to distinguish AM from PM, something to the effect of:

 $shifts['User1']['AM'] = A00A00A;
 $shifts['User1']['PM'] = 0P000P0;

So that the A’s and P’s are both considered set, but that

 A00A00A | 0P000P0 = AP0A0PA;

Is there a common way of doing this, or am I thinking about this totally wrong?

  • 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-31T21:10:03+00:00Added an answer on May 31, 2026 at 9:10 pm

    To represent three states in a binary fashion you need 2 bits. For instance, you could say that:

    PM = 01

    AM = 10

    OFF = 00

    So now you have this:

    A00A00A translates to 10 00 00 10 00 00 10

    0P000P0 translates to 00 01 00 00 00 01 00

    Applying bitwise OR operation:

    10 00 00 10 00 00 10
    00 01 00 00 00 01 00
    --------------------
    10 01 00 10 00 01 10
    A  P  0  A  0  P  A
    

    You get AP0A0PA, your desired result.

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

Sidebar

Related Questions

Good afternoon, This may sound like a silly question, but it would be really
This may be a duplicate question, but really don't know how else to word
I know this may be a stupid question to ask but I have really
I'm new at Matlab. You may find this question silly but I really wonder
This question might seem really silly to most of the enlightened folks here. But
I know this may be really silly - but how can I disable the
I am not sure if this question is not silly, but I really want
This may be a really silly question, but I've found no answer on google/bing...
I know this question may sound silly, but I am learning (at least trying)
This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel

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.