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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:16:41+00:00 2026-06-11T09:16:41+00:00

I’m trying to get basic skills in working with bits using C#.NET. I posted

  • 0

I’m trying to get basic skills in working with bits using C#.NET. I posted an example yesterday with a simple problem that needs bit manipulation which led me to the fact that there are two main approaches – using bitwise operators or using .NET abstractions such as BitArray (Please let me know if there are more build-in tools for working with bits other than BitArray in .NET and how to find more info for them if there are?).

I understand that bitwise operators work faster but using BitArray is something much more easier for me, but one thing I really try to avoid is learning bad practices. Even though my personal preferences are for the .NET abstraction(s) I want to know which i actually better to learn and use in a real program. Thinking about it I’m tempted to think that .NET abstractions are not that bad at, after all there must be reason to be there and maybe being a beginner it’s more natural to learn the abstraction and later on improve my skills with low level operations, but this is just random thoughts.

  • 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-11T09:16:43+00:00Added an answer on June 11, 2026 at 9:16 am

    It really depends on what you are doing with it. I’d say use bitwise operations when speed is more of a concern as they have much less overhead. Otherwise, BitArray’s should be fine. The main overhead associated is function calls and some limits on “tricks” you can do.

    For instance, if you wanted to do something if bits 0, 3, or 4 where set in a value:

    if((value & 0b11001)>0) //not sure this is valid syntax, but you get the idea
    {
       //do stuff
    }
    

    Which because integers are a native CLR type, translates almost directly to just 3 native opcodes, mov, and, and cmp

    where as for a BitArray, the most effecient way I see is this:

    if(value[0] || value[3] || value[4])
    {
      //...
    }
    

    Where (assuming not JIT), this equals up to 3 function calls of light complexity. The simplest way to get a bit value from the backing integer(I assume) of a BitArray looks like this:

    bool GetBit(int which)
    {
      return value & (1 << which)>0;
    }
    

    This basically means it equates to being about 2 times slower for just one bit For this super simple case, this would mean about 6 times slower since we are checking 3 bits.

    And also for BitArrays, copies may be more expensive, as they aren’t a native CLR type. I’d suspect this overhead is JITed away for the most part, but still something to consider, especially if targetting a compact framework.

    Basically, only use BitArrays if you’re not ever going to need to do complex bitwise operations on them.

    Note: you can also use a hybrid approach of converting between integers and BitArrays, but this can have quite a bit of overhead as well.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is

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.