Skip to content

Commit

Permalink
Mejoro formato de la salida del reslutado.
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Montalvo Ochoa <fmontalvoo@ups.edu.ec>
  • Loading branch information
fmontalvoo committed Mar 9, 2021
1 parent a354ae5 commit aae3596
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.fmontalvoo.converter"
minSdkVersion 17
targetSdkVersion 30
versionCode 2
versionName "1.2"
versionCode 3
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ public String convert(String number, int option) {

switch (option) {
case 1:
return binaryToHexadecimal(number);
return formatOutput(binaryToHexadecimal(number));
case 2:
return binaryToDecimal(number);
return formatOutput(binaryToDecimal(number));
case 3:
return binaryToOctal(number);
return formatOutput(binaryToOctal(number));
case 4:
return octalToHexadecimal(number);
return formatOutput(octalToHexadecimal(number));
case 5:
return octalToDecimal(number);
return formatOutput(octalToDecimal(number));
case 6:
return octalToBinary(number);
return formatOutput(octalToBinary(number));
case 7:
return decimalToHexadecimal(number);
return formatOutput(decimalToHexadecimal(number));
case 8:
return decimalToOctal(number);
return formatOutput(decimalToOctal(number));
case 9:
return decimalToBinary(number);
return formatOutput(decimalToBinary(number));
case 10:
return hexadecimalToDecimal(number);
return formatOutput(hexadecimalToDecimal(number));
case 11:
return hexadecimalToOctal(number);
return formatOutput(hexadecimalToOctal(number));
case 12:
return hexadecimalToBinary(number);
return formatOutput(hexadecimalToBinary(number));
default:
return "";
}
Expand Down Expand Up @@ -68,6 +68,10 @@ private String completeBits(String binary) {
return completeBits('0' + binary);
}

private String formatOutput(String input) {
return input.replaceAll("(.{" + "4" + "})", "$1 ").trim();
}

private char characters(int n) {
switch (n) {
case 10:
Expand Down

0 comments on commit aae3596

Please sign in to comment.