Here is a C++ solution, (considering given number is positive and 32-bit integer)
#include <bits/stdc++.h>
usingnamespacestd;intany_odd(unsignedintnumber){return(number&0xAAAAAAAA)!=0;// 0xAAAAAAAA has all its odd bits set, so if result is not 0 then number has at least one odd set bit}intmain(){cout<<any_odd(2)<<"\n";// output -> 1cout<<any_odd(170)<<"\n";// output -> 1cout<<any_odd(5)<<"\n";// output -> 0cout<<any_odd(7)<<"\n";// output -> 1cout<<any_odd(10)<<"\n";// output -> 1cout<<any_odd(0)<<"\n";// output -> 0return0;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is a C++ solution, (considering given number is positive and 32-bit integer)