This is a C Program to multiply given number by 4 using bitwise operators.
This C Program multiplies given number by 4 using bitwise operators.
The bitwise operators are or, and, xor, not, left shift, right shift. Program uses left shift operator for this.
Here is source code of the C program to multiply given number by 4 using bitwise operators. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C program to multiply given number by 4 using bitwise operators */ #include <stdio.h> void main() { long number, tempnum; printf("Enter an integer \n"); scanf("%ld", &number); tempnum = number; /* left shift by two bits */ number = number << 2; printf("%ld x 4 = %ld\n", tempnum, number); }
In this C program, we are reading the integer using ‘number’ variable, and assign the value of ‘number’ variable to ‘tempnum’ variable. The bitwise operators are, or, and, xor, not, left shift, right shift. The program uses left shift operator to the value of ‘number’ variable by two bits.
$ cc pgm62.c $ a.out Enter an integer 450 450 x 4 = 1800
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Practice BCA MCQs
- Apply for Computer Science Internship
- Buy Computer Science Books