From 2fa4cb56c2a4fd656aacfb9626658469d559c992 Mon Sep 17 00:00:00 2001 From: cmirnov Date: Sun, 11 Oct 2015 22:47:52 +0300 Subject: [PATCH 1/4] Create fitsBits --- fitsBits | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 fitsBits diff --git a/fitsBits b/fitsBits new file mode 100644 index 0000000..04ea148 --- /dev/null +++ b/fitsBits @@ -0,0 +1,12 @@ +void fitsBits(){ + int x, n; + scanf("%d%d", &x, &n); + int x2 = ~x; + int cur = 1 << 31; + cur = cur >> (32 - n - 1); + int cur2 = cur; + cur2 = cur2 & x2; + cur = cur & x; + printf("%d\n", !cur + !cur2); + return; +} From f70fe21450e1852ab1f5079e0fc3d8ed485c6f4e Mon Sep 17 00:00:00 2001 From: cmirnov Date: Fri, 23 Oct 2015 11:11:30 +0300 Subject: [PATCH 2/4] Update fitsBits --- fitsBits | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fitsBits b/fitsBits index 04ea148..3a65af8 100644 --- a/fitsBits +++ b/fitsBits @@ -1,12 +1,10 @@ -void fitsBits(){ - int x, n; - scanf("%d%d", &x, &n); +int fitsBits(int x, int n){ int x2 = ~x; int cur = 1 << 31; cur = cur >> (32 - n - 1); int cur2 = cur; cur2 = cur2 & x2; cur = cur & x; - printf("%d\n", !cur + !cur2); - return; + printf("%d", !cur + !cur2); + return 2; } From d661b1973d4b4c6c200bcfabbb6bf702decddcba Mon Sep 17 00:00:00 2001 From: cmirnov Date: Fri, 23 Oct 2015 11:54:02 +0300 Subject: [PATCH 3/4] Update fitsBits --- fitsBits | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fitsBits b/fitsBits index 3a65af8..83384f3 100644 --- a/fitsBits +++ b/fitsBits @@ -5,6 +5,5 @@ int fitsBits(int x, int n){ int cur2 = cur; cur2 = cur2 & x2; cur = cur & x; - printf("%d", !cur + !cur2); - return 2; + return (!cur + !cur2); } From 096d1b801e1028790f801076fce539ed64213535 Mon Sep 17 00:00:00 2001 From: cmirnov Date: Tue, 27 Oct 2015 15:38:46 +0300 Subject: [PATCH 4/4] Update fitsBits --- fitsBits | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fitsBits b/fitsBits index 83384f3..1be7bf5 100644 --- a/fitsBits +++ b/fitsBits @@ -1,9 +1,3 @@ int fitsBits(int x, int n){ - int x2 = ~x; - int cur = 1 << 31; - cur = cur >> (32 - n - 1); - int cur2 = cur; - cur2 = cur2 & x2; - cur = cur & x; - return (!cur + !cur2); + return (!(((x << (33 + ~n)) >> (33 + ~n)) + ~x + 1)); }