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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:52:58+00:00 2026-05-21T13:52:58+00:00

I am aware of the basic premise of what bitwise operation are (although would

  • 0

I am aware of the basic premise of what bitwise operation are (although would appreciate a “for dummies” explanation); however I am unaware of when it is appropriate to use this technique.

My understanding is that older CPU architectures could perform bitwise operations faster then other operations and hence it was advantageous to know how to use them. Given this is no longer the case; is it still appropriate to perform them and if so, for what purpose and under what conditions? (I am specifically interested in the C# context but am happy to receive general answers)

  • 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-21T13:52:58+00:00Added an answer on May 21, 2026 at 1:52 pm

    Bitwise operations are a great way to quickly check for a flag that may be set on a variable.

    The following example highlights the benefits of using bitwise operations on a Flag enumeration as well as storing a bitstuffed field into a database. The bitstuffed field can then easily be checked to see if it contains a single value or subset of values from the Flag enumeration.

    Example:

    A User database table with a tinyint field called Permission. The field is populated using a value created with the enumeration which values are 2^n.

    [Flags]
    public enum Permission : byte
    {
        None = 0,
        ManageUsers = 1 << 0,
        CreateOrders = 1 << 1,
        PurchaseEquipment = 1 << 2,
        CancelOrders = 1 << 3,
    }
    

    Apart from bitwise operations being used to specify values in the enumeration (done at compile time), you can use the enumeration to check if the Permission field in the database contains any subset of the possible values. From the database side you gain the ability to stuff values into a single field – eliminating the need to have a column for each permission and in the code side you gain an easy way to check for a value.

    Example bitstuffing (Grant ManageUsers and CreateOrders):

    Permission userPermissions = Permission.ManageUsers | Permission.CreateOrders;
    

    Example permission check:

    public bool HasPermissions(Permission userPermissions, Permission permissionsToCheckFor)
    {
        return permissionsToCheckFor == Permission.None ? 
            false : 
            (userPermissions & permissionsToCheckFor) == permissionsToCheckFor;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a basic WCF service in IIS. I am aware that this
I am aware this is a very basic question, we are very new to
I am aware that this is a very basic question, but an interviewer asked
I aware that this will be a less programming question, but still... How can
Context I am aware of http://closure-library.googlecode.com/svn/trunk/closure/goog/demos/editor/equationeditor.html# However, when I try it, it does not
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic
I am aware of the basic dirty indicator methods for rails, which work if
This might be a basic question but i wanted to ask since i am
I wrote this very basic programm to examine what the compiler is doing behind
I think the following is a basic problem. I using this number Picker as

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.