File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
main/java/cn/byhieg/bitoperatetutorial
test/java/cn/byhieg/bitoperatetutorialtest Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments