
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- C++ Program to Perform Addition Operation Using Bitwise Operators
- C program to print multiplication table by using for Loop
- Checking power of 2 using bitwise operations in JavaScript
- C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers
- C++ program to find addition and subtraction using function call by address
- Bitwise recursive addition of two integers in C
- C Program for Matrix Chain Multiplication
- How to multiply a given number by 2 using Bitwise Operators in C#?
- C++ program for multiplication of array elements
- Program to find maximum score from performing multiplication operations in Python
- Alternate addition multiplication in an array - JavaScript
- Python Program for Find reminder of array multiplication divided by n
- Performing Bitwise Operations with BigInteger in Java
- Explain the commutative and associative properties of addition and multiplication of integers.
- Matrix Multiplication and Normalization in C program

Advertisements