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
  • 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. 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

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You dereference a char *, resulting in a char, and… May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer While I didn't hide it, I did find another way… May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer eq expects a numerical index to only return a single… May 11, 2026 at 6:29 pm

Related Questions

I'm trying to write some STL data out of matlab and I'm trying to
I was reading about output buffering in JavaScript here , and was trying to
I was reading about App Engine on wikipedia and came across some GQL restrictions:
I was reading about parsers and parser generators and found this statement in wikipedia's

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.