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

  • Home
  • SEARCH
  • 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 9141447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:38:45+00:00 2026-06-17T09:38:45+00:00

While learning the flag technique, I encountered some problem, hereby I’m showing this example

  • 0

While learning the flag technique, I encountered some problem, hereby I’m showing this example using C#, with Enum:

   [Flags]
    enum PermissionTypes : byte
    {
        None = 0x0,
        Read = 0x1,
        Write = 0x2,
        Modify = 0x4,
        Delete = 0x8,
        Create = 0x10,
        All = Read | Write | Modify | Delete | Create
    }

To check hasFlag property:

if((value & mask) == mask) {...}

But when ‘hasFlag’ applied on both ‘None’ and ‘Read’:

Denote x = Current_Permission_Setting,

x & PermissionTypes.None = always false
x & PermissionTypes.Read = always true IFF 

(cont’) IFF x = {ODD byte value}


Question: What are the perfect sets of flag values that are safe to be used?


Reference:
Here’s the full example.

  • 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-17T09:38:46+00:00Added an answer on June 17, 2026 at 9:38 am

    As @antlersoft says in the comments, you can’t really use NONE as a bitflag.
    The rest of your flags make sense. You do need to use the powers of 2 to get 1 bit per flag.

    It doesn’t make sense to test for “Has READ and NONE” set, anyway, since NONE implies READ is not set.

    The problem you describe with odd values of X doesn’t seem to make sense. The value will only be odd if bit 1 is set. If you are using your flags consistently, bit 1 will only be set if READ is true.

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

Sidebar

Related Questions

While learning Rails, I found this example in the Sam Ruby's book: app/controllers/line_items_controller.rb def
HI there! I've run into some problem while learning to combine .sh files and
Sorry since this question is specific to my problem. While learning reflections i did
While learning Prolog, I'm trying to solve the following problem, using accumulators: Write a
While learning C# pretty fast, I am stumbling on this Collection syntax problem. I
I am facing some odd problems while learning SQLAlchemy. I am using 0.7.2 version
While learning an example from learn-you-a-haskell which right triangle that has integers for all
i just got some more questions while learning PHP, does php implement any built
I've slightly modified the iPhone SDK's GLSprite example while learning OpenGL ES and it
So I found some similarities between arrays and set notation while learning about sets

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.