-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday13_2.java
More file actions
40 lines (29 loc) · 811 Bytes
/
day13_2.java
File metadata and controls
40 lines (29 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//User function Template for Java
class Solution {
static Long reversedBits(Long X) {
// code here
String binary = Long.toBinaryString(X);
String padding = String.format("%32s", binary).replace(' ', '0');
String str ="";
for(int i=padding.length()-1;i>=0; i--)
{
str=str+Character.toString(padding.charAt(i));
}
Long ans = Long.parseLong(str,2);
return ans;
}
};
/*
Given a 32 bit number X, reverse its binary form and print the answer in decimal.
Example 1:
Input:
X = 1
Output:
2147483648
Explanation:
Binary of 1 in 32 bits representation-
00000000000000000000000000000001
Reversing the binary form we get,
10000000000000000000000000000000,
whose decimal value is 2147483648.
*/