binary representation differ in bits
C++
// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
// compute number of different bits
void solve(int A, int B)
{
int count = 0;
// since, the numbers are less than 2^31
// run the loop from '0' to '31' only
for (int i = 0; i < 32; i++) {
// right shift both the numbers by 'i' and
// check if the bit at the 0th position is different
if (((A >> i) & 1) != ((B >> i) & 1)) {
count++;
}
}
cout << "Number of different bits : " << count << endl;
}
// Driver code
int main()
{
int A = 12, B = 15;
// find number of different bits
solve(A, B);
return 0;
}
Also in C++:
- Title
- substr c++
- Category
- C++
- Title
- how to print to the serial monitor arduino
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- c++ char to int
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ clear stream
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- run cmd command c++
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- length of string c++
- Category
- C++
- Title
- function template
- Category
- C++
- Title
- array search c++
- Category
- C++
- Title
- swapo algorit
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- trovare il valore massimo in un array c++ w3
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- convert decimal to binary in c++
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- linear search in c++
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- inheritance protected in c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- preorder traversal c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- c++ loop through array
- Category
- C++
- Title
- c++ replace n substrings
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- c++ round to int
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- comparing strings c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- int to float c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- what does map.count() return in c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- char size length c++
- Category
- C++
- Title
- initialising 2d vector
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- Html tab
- Category
- C++
- Title
- stack function in cpp
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- copy a part of a vector in another in c++
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++