Skip to content

Commit 2dc208e

Browse files
authored
Create binary
1 parent 19545ce commit 2dc208e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

binary

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Solution {
2+
3+
public String findDigitsInBinary(int a) {
4+
5+
StringBuilder binary = new StringBuilder();
6+
String s;
7+
if(a==0)
8+
{ s="0";
9+
10+
return s; }
11+
12+
while (a>0) {
13+
if((a&1)==1){
14+
binary.append(1);
15+
}else
16+
binary.append(0);
17+
a>>=1;
18+
}
19+
binary.reverse();
20+
s= binary.toString();
21+
return s;
22+
23+

0 commit comments

Comments
 (0)