Write a function using bitwise opetators to check whether an integer is a power of 2 or not?

1 answer

Answer

1043731

2026-07-13 09:31

+ Follow

sol 1:
return(if(x!=0)&&!(x&(x-1));
sol 2:
return(if(x!=0)&&(x&(~x+)));

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.