Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
prittoruban
Java_Programs
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Java_Programs
/
IntegerConcatenateBitsinReverse.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
26 lines (21 loc) · 853 Bytes
main
Breadcrumbs
Java_Programs
/
IntegerConcatenateBitsinReverse.java
Copy path
Top
File metadata and controls
Code
Blame
26 lines (21 loc) · 853 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import java.math.BigInteger;
public class IntegerConcatenateBitsinReverse {
public static void main(String[] args) {
int X = 10;
int Y = 6;
String binaryX = new StringBuilder(Integer.toBinaryString(X)).reverse().toString();
String binaryY = new StringBuilder(Integer.toBinaryString(Y)).reverse().toString();
StringBuilder B = new StringBuilder();
int maxLength = Math.max(binaryX.length(), binaryY.length());
for (int i = 0; i < maxLength; i++) {
if (i < binaryX.length()) {
B.append(binaryX.charAt(i));
}
if (i < binaryY.length()) {
B.append(binaryY.charAt(i));
}
}
BigInteger decimalB = new BigInteger(B.toString(), 2);
System.out.println(decimalB);
}
}
You can’t perform that action at this time.