The Wayback Machine - https://web.archive.org/web/20071217073958/http://www.codeguru.com:80/cpp/cpp/cpp_mfc/bits/article.php/c4087/

CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
Complex Webhosting
Boat Donations
Domains for Business
Promotional Pens
Rackmount LCD Monitor
Freelance Programmers
Dental Insurance
Domain registration
Career Education
Data Center Solutions
Shop
Internet Security
Build a Server Rack
Televisions


RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Access FREE Intel Whitepapers and Briefs at the Intel Resource Center
Whitepaper:
Reduce Maintenance Costs While Increasing Notebook Security

Whitepaper:
Improve Security and Control of Your Desktop PC

Mobility Whitepaper:
Increase Performance, Security with Intel Centrino Pro Processor Technology

Servers/Workstations Whitepaper:
Wireless Technologies and e-Learning--Bridging the Digital Divide

Servers/Workstations Whitepaper:
Which Is Right for You--Itanium 2 or x86 Architecture?

Clients Whitepaper:
Intel Centrino Pro and Intel vPro Processor Technology

Virtualization eBook:
Using Virtualization to Change the Face of Business

Virtualization Whitepaper: IT Agility through Automated, Policy-based Virtual Infrastructure
Home >> Visual C++ / C++ >> C++ >> C++ & MFC >> Bits and Bytes

Fluke Networks Whitepaper: Locating Rogue Wireless Access Points. An unauthorized, rogue access point can compromise the security of a wireless network. Learn how to remove this security vulnerability.

Representing Arrays as Streams of Bits
Rating:

Alexander Hritonenkov (view profile)
March 31, 2003

Environment: MFC

I wrote this class when I needed to extract separate bits of data from an array, one by one. After some calculations, I found I needed to put modified bits in another array of data. I think this class may be useful, so here it is.


(continued)




Usability and Design
The Usability and design space brings together the latest information, research, tools, podcasts, and conference information related to usability and design. Content is pulled from IBM and non-IBM sites. »
 
Ajax Resource Center
This space is your one-stop shop for information on the Ajax programming model, including articles and tutorials, discussion forums, blogs, wikis, events, and news. If it's happening, it's covered here. »
 
Linux Security
The Linux security space gives an overview of security issues related to Linux and covers all aspects of securing a Linux distribution. It also links to Linux security-related news and articles. »
 
Ruby Programming
Take a closer look at Ruby, a dynamic programming language that is growing rapidly in popularity. Explore its intriguing features and learn what programmers are doing with it. »
 
Wiki: WebSphere, SOA, J2EE in Practice
This wiki discusses how to use J2EE and related technologies to develop business applications, including how to make best use of IBM J2EE products like WebSphere Application Server and Rational Application Developer, and IBM SOA products like WebSphere Process Server and WebSphere Integration Developer. While it occasionally delves into tangential topics and future trends, the primary focus is on how to make use of the products and technologies that we have today. »

This class operates with data located in the CByteArray object. So, the common steps to use CBitStream are:

  1. Declare a CByteArray object.
  2. Declare a CBitStream object, supplying a reference to the newly created CByteArray object to the constructor of the first one.
  3. Enjoy. :)

To set/get the next bit, you can use either overloaded shifting operators or SetBit()/GetBit() functions. Also, you can navigate inside the array of data. You can set a "pointer" to any bit inside your array.

Also, you can choose the order in which bits of every byte will be processed. The default is a "left-to-right" order. In this order, the bits affected are: 7th, 6th, 5th, 4th, 3rd, 2nd, 1st, and then the 0 bit. You can define the RIGHTTOLEFTFILL identifier to change the order to right-to-left, in which bits are accessed: 0, 1st, 2nd, 3rd, 4th, 5th, 6th, and then 7th. I prefer the left-to-right order because it is easier to understand. Look to the picture below. a) is the left-to-right order (default) and b) is the right-to-left order.

CByteArray array;
CBitStream stream(array);

stream<<0<<1<<0<<0<<1<<0<<0<<1;
// The first byte now consists of 01001001 bits, so it equals 73
// (0x49). It's true when you are using the left-to-right order.
stream.SetBit(0);
stream.SetBit(1);
stream.SetBit(0);
stream.SetBit(0);
stream.SetBit(1);
stream.SetBit(0);
stream.SetBit(0);
stream.SetBit(1);
// The second byte is now the same as the first.

Downloads

Download demo project - 10 Kb
Download source - 3 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

Article: Components and Shared Services Make SIP Development Seamless
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance
Article: Create Highly-Available J2EE Applications -- See how Avaya's SIP A/S can help.


RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Good - Legacy CodeGuru (04/01/2003)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)
Oracle Information-Driven Business Center:
EBOOK:
Migrating to Oracle Database 11g
Preparing for a database migration? Read this first.
WHITEPAPER:
Information Lifecycle Management with Oracle Database 11g
WHITEPAPER:
Oracle Database 11g High Availability
Learn how you can reach your high availability requirements.
WHITEPAPER:
Oracle Database 11g Solutions for Security and Compliance


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info