Open Source Technical Information: How will check a no. is of the format 2^i - 2^j ......Single line code ..... ?

Friday, 21 October 2011

How will check a no. is of the format 2^i - 2^j ......Single line code ..... ?

,
1st Way:- 
using Loop:-
let the given number is n;
while(n&(n%2==0?n/=2:0) || ! printf("%s", n&(n+1)?"no":"yes")) ; 

2nd Way:-
 Without Loop:-
‎(((n-1)|n)+1) &n ==0



 

0 comments to “How will check a no. is of the format 2^i - 2^j ......Single line code ..... ?”

Post a Comment

Write your tips here...

Deal of the Day

Advertisement here

Advertisement here