Skip to content

Commit 903f467

Browse files
committed
添加位运算
1 parent 8901ce7 commit 903f467

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cn.byhieg.bitoperatetutorial;
2+
3+
/**
4+
* Created by byhieg on 2017/6/27.
5+
* Mail to byhieg@gmail.com
6+
*/
7+
public class BitOperate {
8+
9+
10+
public String getRightestOne(int n){
11+
int res = n & (~n + 1);
12+
return Integer.toBinaryString(res);
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.byhieg.bitoperatetutorialtest;
2+
3+
import cn.byhieg.bitoperatetutorial.BitOperate;
4+
import junit.framework.TestCase;
5+
6+
/**
7+
* Created by byhieg on 2017/6/27.
8+
* Mail to byhieg@gmail.com
9+
*/
10+
public class BitOperateTest extends TestCase {
11+
12+
BitOperate bitOperate;
13+
@Override
14+
protected void setUp() throws Exception {
15+
super.setUp();
16+
bitOperate = new BitOperate();
17+
}
18+
19+
public void testGetRightestOne() throws Exception {
20+
assertEquals(bitOperate.getRightestOne(Integer.valueOf("100100",2)),"100");
21+
}
22+
23+
}

0 commit comments

Comments
 (0)