 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program for Addition and Multiplication by 2 using Bitwise Operations.
Bitwise operators operate on bits (i.e. on binary values of on operand)
| Operator | Description | 
|---|---|
| & | Bitwise AND | 
| | | Bitwise OR | 
| ^ | Bitwise XOR | 
| << | Left Shift | 
| >> | Right Shift | 
| - | One's complement | 
| Bitwise AND | ||
|---|---|---|
| a | b | a & b | 
| 0 | 0 | 0 | 
| 0 | 1 | 0 | 
| 1 | 0 | 0 | 
| 1 | 1 | 1 | 
| Bitwise OR | ||
|---|---|---|
| a | b | a | b | 
| 0 | 0 | 0 | 
| 0 | 1 | 1 | 
| 1 | 0 | 1 | 
| 1 | 1 | 1 | 
| Bitwise XOR | ||
|---|---|---|
| a | b | a ^ b | 
| 0 | 0 | 0 | 
| 0 | 1 | 1 | 
| 1 | 0 | 1 | 
| 1 | 1 | 0 | 

Example
Following is the C program for addition and multiplication by 2 with the help of bitwise operators −
#include<stdio.h> main(){    int a;    printf("Enter a
");    scanf("%d",&a);    printf("%d*2=%d 
",a,a<<1);    printf("%d/2=%d 
",a,a>>1); }  Output
When the above program is executed, it produces the following output −
Run 1: Enter a 45 45*2=90 45/2=22 Run 2: Enter a 65 65*2=130 65/2=32
Advertisements
 