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

C program for addition and multiplication using bitwise operations

PHPz
Release: 2023-09-16 19:49:01
forward
1041 people have browsed it

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);
}
Copy after login
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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template