What is a simple program that uses C language to display the left shift, right shift, and complement of a number?
If the value of a variable is shifted to the left once, its value will be doubled.
For example, a = 10, then a
If the value of a variable is shifted right once , then its value becomes half of its original value.
For example, a = 10, then a>>1 = 5
The following is C for shift operation Program-
Live Demonstration
#include<stdio.h> main (){ int a=9; printf("Rightshift of a = %d</p><p>",a>>1);//4// printf("Leftshift of a = %d</p><p>",a<<1);//18// printf("Compliment of a = %d</p><p>",~a);//-[9+1]// printf("Rightshift by 2 of a = %d</p><p>",a>>2);//2// printf("Leftshift by 2 of a = %d</p><p>",a<<2);//36// }
When the above program is executed, the following results will be produced-
Rightshift of a = 4 Leftshift of a = 18 Compliment of a = -10 Rightshift by 2 of a = 2 Leftshift by 2 of a = 36
The above is the detailed content of What is the displacement operation in C language?. For more information, please follow other related articles on the PHP Chinese website!