Home  >  Article  >  Backend Development  >  C program for addition and multiplication using bitwise operations

C program for addition and multiplication using bitwise operations

PHPz
PHPzforward
2023-09-16 19:49:011001browse

Bitwise operators operate on bits (that is, operate on the binary value of the operand)

##&Bitwise AND##|^>>-
Operator Description
Bitwise OR
Bitwise XOR
Shift left
Shift right
Complement code

##Bitwise and aba & b0 00010100111

##Bitwise orab00011101 tr>1Bitwise XOR
a | b ## 0
##1 1
##a ba^b00001101 110The following is the C Program for Addition and Multiplication 2 using Bitwise Operators -
1
##Example
Live Demonstration

#include<stdio.h>
main(){
   int a;
   printf("Enter a</p><p>");
   scanf("%d",&a);
   printf("%d*2=%d </p><p>",a,a<<1);
   printf("%d/2=%d </p><p>",a,a>>1);
}
C program for addition and multiplication using bitwise operations Output

When the above program is executed, the following output is produced -

Run 1:
Enter a
45
45*2=90
45/2=22
Run 2:
Enter a
65
65*2=130
65/2=32

The above is the detailed content of C program for addition and multiplication using bitwise operations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete

Related articles

See more