I was wondering how would you change a binary number and reverse the 1’s and 0’s? I know how to change an integer number into binary already
Example 1: 5 as a parameter would return 2
Steps: 5 as a binary is 101
The complement is 010
010 as an integer is 2
Code to change an integer to a binary number
import java.io.*;
public class DecimalToBinary{
public static void main(String args[]) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String bynumber = Integer.toBinaryString(i);
System.out.println("Binary: " + bynumber);
}
}
if anyone code please help, thank you!
Use the bitwise not function
~.