вроде все работает но пишет что не все условия выполняются? может нужно дописать код чтобы число в 16-ричной системы было из 4 цифр?
package com.javarush.task.pro.task09.task0908;
import java.util.regex.Pattern;
/*
Двоично-шестнадцатеричный конвертер
*/
public class Solution {
public static void main(String[] args) {
String binaryNumber = "100111010000";
System.out.println("Двоичное число " + binaryNumber + " равно шестнадцатеричному числу " + toHex(binaryNumber));
String hexNumber = "9d0";
System.out.println("Шестнадцатеричное число " + hexNumber + " равно двоичному числу " + toBinary(hexNumber));
}
public static String toHex(String binaryNumber) {
String line = "0000000100100011010001010110011110001001101010111100110111101111";
String hex = "0123456789abcdef";
String toHex = "";
boolean chec=false;
if (binaryNumber=="" | binaryNumber==null){
return toHex;
}
for (int i=0; i<binaryNumber.length(); i++){
if(binaryNumber.charAt(i)!=48 && binaryNumber.charAt(i)!=49){
chec=true;
}
}
if (chec==true ){
return toHex;
}//напишите тут ваш код
else {
if (binaryNumber.length()%4 !=0){
do {
binaryNumber=0+binaryNumber;
}
while(binaryNumber.length()%4 ==0);
}
for(int i=0; i<binaryNumber.length()/4; i++){
for(int e=0; e<line.length()/4;e++){
int a = 4*i;
int b=a+4;
String qw = binaryNumber.substring(a, b);
int c=4*e;
int d=c+4;
String qwer = line.substring(c, d);
if(qw.equals(qwer)){
toHex=toHex+hex.charAt(e);
}
}
}
}
return toHex;
}
public static String toBinary(String hexNumber) {
String toBinary = "";
boolean chec=false;
String hex = "0123456789abcdef";
String line = "0000000100100011010001010110011110001001101010111100110111101111";
if (hexNumber=="" | hexNumber==null){
return toBinary;
}
for (int i=0; i<hexNumber.length(); i++){
if(chec==true)
break;
for(int e=0; e<hex.length();e++){
if (hexNumber.charAt(i)==hex.charAt(e)){
chec = false;
break;
}
else
chec = true;
}
}
if (chec==true );
else {
for(int i =0; i< hexNumber.length(); i++){
for(int e=0; e< hex.length();e++){
int c=4*e ;
int d =c+4 ;
if(hexNumber.charAt(i)==hex.charAt(e)){
toBinary=toBinary+line.substring(c, d);
}
}
}
}//напишите тут ваш код
return toBinary;//напишите тут ваш код
}
}