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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:33:17+00:00 2026-05-11T08:33:17+00:00

I was reading about flag enums and bitwise operators, and came across this code:

  • 0

I was reading about flag enums and bitwise operators, and came across this code:

enum file{ read = 1, write = 2, readandwrite = read | write } 

I read somewhere about why there is a inclusive or statement and how there can’t be an &, but can’t find the article. Can someone please refresh my memory and explain the reasoning?

Also, how can I say and/or? Eg. if dropdown1=’hello’ and/or dropdown2=’hello’….

Thanks

  • 1 1 Answer
  • 3 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. 2026-05-11T08:33:18+00:00Added an answer on May 11, 2026 at 8:33 am

    First Question:

    A | does a bitwise or; a bit will be set in the result if it is set in the first value or the second value. (You use it on enums to create values that are combinations of other values) If you were to use a bitwise and, it wouldn’t make very much sense.

    It gets used as follows:

    [Flags]  enum FileAccess{ None = 0,                    // 00000000 Nothing is set Read = 1,                    // 00000001 The read bit (bit 0) is set Write = 2,                   // 00000010 The write bit (bit 1) is set Execute = 4,                 // 00000100 The exec bit (bit 2) is set // ... ReadWrite = Read | Write     // 00000011 Both read and write (bits 0 and 1) are set // badValue  = Read & Write  // 00000000 Nothing is set, doesn't make sense ReadExecute = Read | Execute // 00000101 Both read and exec (bits 0 and 2) are set } // Note that the non-combined values are powers of two, \ // meaning each sets only a single bit  // ...  // Test to see if access includes Read privileges: if((access & FileAccess.Read) == FileAccess.Read) 

    Essentially, you can test if certain bits in an enum are set; in this case we are testing to see if the bits corresponding to a Read are set. Values Read and ReadWrite would both pass this test (the both have bit zero set); Write would not (it does not have bit zero set).

    // if access is FileAccess.Read         access & FileAccess.Read == FileAccess.Read //    00000001 &        00000001 => 00000001  // if access is FileAccess.ReadWrite         access & FileAccess.Read == FileAccess.Read //    00000011 &        00000001 => 00000001  // uf access is FileAccess.Write         access & FileAccess.Read != FileAccess.Read //    00000010 &        00000001 => 00000000 

    Second Question:

    I think when you say ‘and/or’, you mean ‘one, the other or both’. This is exactly what the || (or operator) does. To say ‘one or the other, but not both’, you’d use ^ ( the exclusive or opertor).

    Truth tables (true==1, false==0):

         A   B | A || B       ------|------- OR   0   0 |    0      0   1 |    1       1   0 |    1      1   1 |    1 (result is true if any are true)       A   B | A ^ B       ------|------- XOR  0   0 |    0      0   1 |    1       1   0 |    1      1   1 |    0  (if both are true, result is false) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading the erlang documentation about file io and saw this: On operating
You might be reading this and about to flag it as a duplicate but
When reading about JQuery best practices, I read this recently: Never include Javascript events
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
While reading about exception, I will always come across checked exceptions and unchecked exceptions,
I am reading about COFF file formats, which is commonly used to create an
This is mostly curiosity, but I've been reading about the history of Visual Studio
I keep reading about how biased locking, using the flag -XX:+UseBiasedLocking , can improve

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.