2進数を変更して、1と0を逆にするにはどうすればよいでしょうか。整数を2進数に変更する方法をすでに知っています
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
整数を2進数に変更するコード
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);
}
}
誰かコードが助けてくれたら、ありがとう!