We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc2ad73 commit e131cf7Copy full SHA for e131cf7
reverse-bits/sora0319.java
@@ -0,0 +1,14 @@
1
+public class Solution {
2
+ // you need treat n as an unsigned value
3
+ public int reverseBits(int n) {
4
+ String binary = String.format("%32s", Integer.toBinaryString(n)).replace(' ', '0');
5
+ System.out.println(binary);
6
+
7
+ StringBuilder sb = new StringBuilder(binary);
8
+ sb.reverse();
9
10
11
+ return Integer.parseUnsignedInt(sb.toString(),2);
12
+ }
13
+}
14
0 commit comments