From 70a96f02b60634987ccd7cd8e16011c528c9af02 Mon Sep 17 00:00:00 2001 From: cmirnov Date: Thu, 15 Oct 2015 22:15:36 +0300 Subject: [PATCH 1/2] Create isPower2 --- isPower2 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 isPower2 diff --git a/isPower2 b/isPower2 new file mode 100644 index 0000000..b137073 --- /dev/null +++ b/isPower2 @@ -0,0 +1,4 @@ +int isPower2(int x){ + printf("%d", (!((x & (~x + 1)) + (~x + 1)))); + return 2; +} From 63e1c6122567cc8a74fde53e28648f7e25f54a76 Mon Sep 17 00:00:00 2001 From: cmirnov Date: Thu, 3 Dec 2015 21:27:27 +0300 Subject: [PATCH 2/2] Update isPower2 --- isPower2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/isPower2 b/isPower2 index b137073..025b796 100644 --- a/isPower2 +++ b/isPower2 @@ -1,4 +1,4 @@ int isPower2(int x){ - printf("%d", (!((x & (~x + 1)) + (~x + 1)))); - return 2; + int res = ((!((1 << 31) & x)) & (!(x & (x + (~0)))) & (!!x)); + return res; }