回答編集履歴
2
別解の追加
answer
CHANGED
@@ -6,4 +6,7 @@
|
|
6
6
|
|
7
7
|
int main(void) { printf("%d\n", lastBitPos(0xebd6fc00)); }
|
8
8
|
```
|
9
|
-
1 がない場合 0 を返します。
|
9
|
+
1 がない場合 0 を返します。
|
10
|
+
|
11
|
+
[追記]
|
12
|
+
log2(x-1 ^ x) は log2(-x & x) でも構いません。
|
1
コードの修正
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#include <stdio.h>
|
3
3
|
#include <math.h>
|
4
4
|
|
5
|
-
int lastBitPos(unsigned x) { return x ? (int)log2(x-1
|
5
|
+
int lastBitPos(unsigned x) { return x ? (int)log2(x-1 ^ x) + 1 : 0; }
|
6
6
|
|
7
7
|
int main(void) { printf("%d\n", lastBitPos(0xebd6fc00)); }
|
8
8
|
```
|