Fix bug convertEncoding

This commit is contained in:
Divlo 2019-10-05 17:29:27 +02:00
parent 12f06d4dc3
commit cabf5239a3
2 changed files with 48 additions and 30 deletions

View File

@ -215,36 +215,54 @@ try {
}
// Convertis des nombres de différents bases
function convertDecimalBinaryHexadecimal(value, option) {
try {
if (option === 'DecimalToBinary') {
value = value.replace(" ", "");
return parseInt(value).toString(2);
try {
if (option === 'DecimalToBinary') {
value = value.replace(" ", "");
value = parseInt(value);
if (isNaN(value)) {
return messageError;
} else {
return value.toString(2);
}
}
else if (option === 'BinaryToDecimal') {
return parseInt(value, 2);
}
else if (option === 'DecimalToHexadecimal') {
value = value.replace(" ", "");
value = parseInt(value);
if (isNaN(value)) {
return messageError;
} else {
return value.toString(16).toUpperCase();
}
}
else if (option === 'HexadecimalToDecimal') {
return parseInt(value, 16);
}
else if (option === 'BinaryToHexadecimal') {
value = parseInt(value, 2);
if (isNaN(value)) {
return messageError;
} else {
return parseInt(value).toString(16).toUpperCase();
}
}
else if (option === 'HexadecimalToBinary') {
value = parseInt(value, 16);
if (isNaN(value)) {
return messageError;
} else {
return parseInt(value).toString(2);
}
}
else {
return messageError;
}
}
else if (option === 'BinaryToDecimal') {
return parseInt(value, 2);
catch (error) {
return messageError;
}
else if (option === 'DecimalToHexadecimal') {
value = value.replace(" ", "");
return parseInt(value).toString(16).toUpperCase();
}
else if (option === 'HexadecimalToDecimal') {
return parseInt(value, 16);
}
else if (option === 'BinaryToHexadecimal') {
value = parseInt(value, 2);
return parseInt(value).toString(16).toUpperCase();
}
else if (option === 'HexadecimalToBinary') {
value = parseInt(value, 16);
return parseInt(value).toString(2);
}
else {
return messageError;
}
}
catch (error) {
return messageError;
}
}
// Convertis un nombre arabe en nombre romain

View File

@ -182,7 +182,7 @@ $(function () {
{
if (option === 'DecimalToBinary' || option === 'BinaryToDecimal' || option === 'DecimalToHexadecimal' || option === 'HexadecimalToDecimal' || option === 'BinaryToHexadecimal' || option === 'HexadecimalToBinary') {
let result = convertDecimalBinaryHexadecimal(value, option);
if (result === messageError || isNaN(result)) {
if (result === messageError) {
$('.results').html(messageError);
} else {
$('.results').html(result);