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.
2 parents 753eca4 + 21cddee commit b97d9bfCopy full SHA for b97d9bf
reverse-bits/jinhyungrhee.java
@@ -0,0 +1,15 @@
1
+public class Solution {
2
+ // you need treat n as an unsigned value
3
+ public int reverseBits(int n) {
4
+ String intStr = String.valueOf(n);
5
+ String binStr = String.format("%32s", Integer.toBinaryString(n)).replace(" ", "0");
6
+
7
+ String reversedBinStr = "";
8
+ for (int i = 31; i >= 0; i--) {
9
+ reversedBinStr += binStr.charAt(i);
10
+ }
11
12
+ Integer reversedInt = Integer.parseUnsignedInt(reversedBinStr, 2);
13
+ return reversedInt;
14
15
+}
0 commit comments