Published online by Cambridge University Press: 17 July 2025
Until now we have dealt with various operators. All these operators are operated on constants and variables of different data types, i.e., they are operated on byte level. But we are not able to get scope to see within these data types that how they are actually constructed with the individual bits. Also we are not able to set the individual bits within the bytes. If we write int x = 5; we know that the binary equivalent of 5, i.e., 101 will be stored in some memory location named x. As it is an integer variable it occupies 2 bytes of memory. So the total bit pattern of it will be 00000000 00000101. We know it but are never able to test that whether it is the actual bit pattern or not. This is an example but it was not possible for us to check or set the individual bit. But bit level operation is very important when a program interacts directly with the hardware. In this chapter, we will learn about bit by bit manipulation.
Another important feature of C language is it provides a set of operators that operate on individual bits of a variable. They are known as bitwise operators. Apart from hardware interaction these operators help us to save memory and make some computation faster. But these operators can only be applied to integral operands, i.e., integer and character operands, whether signed or unsigned.
To save this book to your Kindle, first ensure no-reply@cambridge-org.demo.remotlog.com is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.