Write a program to Bitwise Operators
Example 1:
Input: a=10,b=25
Output: a|b= 27 , a&b=8 ,a^b=19
Approach:
Java
public class BitwiseOperators {public static void main(String[] args) {int a = 10;int b = 25;// if any one is 1 then the// result is 1 for orSystem.out.println("a|b is " + (a | b));// if both are set then the result// is set else result is unsetSystem.out.println("a&b is " + (a & b));// if one is set and other is// unset then the result is// 1 else 0System.out.println("a^b is " + (a ^ b));}}
C++
#include <bits/stdc++.h>using namespace std;int main(){int a=10;int b=25;//if any one is 1 then the//result is 1 for orcout<<"a|b is "<<(a|b)<<"\n";//if both are set then the result//is set else result is unsetcout<<"a&b is "<<(a&b)<<"\n";//if one is set and other is//unset then the result is//1 else 0cout<<"a^b is "<<(a^b)<<"\n";return 0;}
No comments:
Post a Comment