C++
  Home arrow C++ arrow Bitwise Operators in Action
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Bitwise Operators in Action
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-03

    Table of Contents:
  • Bitwise Operators in Action
  • Do You Need Them?
  • How To
  • In Algorithms

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Bitwise Operators in Action


    (Page 1 of 4 )

    Whether we like it or not, our society is money-oriented. Earning money takes time, and time has its limits; none of us has more of it. So if you want to maximize what you're earning, you must improve your speed. Bitwise operators may not always be the best choice for this, but in some cases relying on them will pay off quite handsomely.

    In this article, which by the way is the second part of a two-part series that began with an article on bitwise operators, I’ll show you why, where, and how to use them, so you’ll get the most out of them. If you missed the first part, please seek it out; it was published here on ASP Free just last week under the name  "Bitwise Operators." The information presented there is necessary to comprehending this article. I’ll presume familiarity with that article already.

    To start with, I’ll present the benefits and drawbacks of the bitwise operators, followed by their usage in programming generally, and summing up with their role in algorithms. So if you want to know when to use bitwise operators and what benefits you’ll get, then just read on and enjoy the ride.

    When, Where, Why?

    The most important property of bitwise operators is that they are executed really fast, mainly because they allow such low-level access to the memory. From this comes one of their main uses, in otherwise slow algorithms. Speeding up every little operation in an algorithm with bitwise operators can result in its running twice as fast -- or even faster. 

    The only glitch in this is that many operators are aware of this, and automatically transform an operation like dividing with 8 to shifting with 3. Also, some argue that by using bitwise operators, the code snippet will become a little overcomplicated and not everybody can follow it, so it brings more disadvantage than benefit.

    And we didn’t even mention what we discussed in the first part of this two-part article series, that “right shifting” can be a dangerous game to play; its implementation is device-dependent, and because of this, your code will become less portable. This is a potentially serious drawback; nowadays, cross-platform compatibility is becoming more of a general requirement to target a larger segment of the marketplace.

    More C++ Articles
    More By Gabor Bernat


     

    C++ ARTICLES

    - More Tricks to Gain Speed in Programming Con...
    - Easy and Efficient Programming for Contests
    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek