Home arrow C++ arrow Bitwise Operators in Action

Bitwise Operators in Action

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.

Author Info:
By: Gabor Bernat
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
March 03, 2009
  1. · Bitwise Operators in Action
  2. · Do You Need Them?
  3. · How To
  4. · In Algorithms

print this article

Bitwise Operators in Action
(Page 1 of 4 )

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値l show you why, where, and how to use them, so you値l 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値l presume familiarity with that article already.

To start with, I値l 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値l 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稚 even mention what we discussed in the first part of this two-part article series, that 途ight 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.

blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- 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++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials