Fix bug convertEncoding
This commit is contained in:
		| @@ -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; | ||||
|         } | ||||
|     }  | ||||
|     catch (error) { | ||||
|         return messageError; | ||||
|     } | ||||
|     else if (option === 'BinaryToDecimal') { | ||||
|     return parseInt(value, 2); | ||||
|     } | ||||
|     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 | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user