16.5 BIT MANIPULATION

In early days of computers, bit manipulation was very important topic. Memory at that time was very costly. Most of the computers had few kilobytes to work with. Therefore, designers used to put as much information as possible in a single byte. Different bits or their groups use to store certain information. Hence, manipulating bits was an important programming activity.

Most of the times, we will be dealing with a byte. Since it is not a built-in data type, let us define it with typedef. Consider the following declaration.

typedef unsigned char BYTE ;

This will enable us to deal with bytes elegantly. A byte will store unsigned integers between 0 and 255. However, we are interested in bit pattern. We will develop a function ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.