I have an app Base calculator and I'm facing an issue with subtraction between two base hexadecimal. if a (big number subtraction a small number) it gives the correct result. the problem is when the operation ( small number subtraction big number ) for Example: (1 - 22 or 1a - 22 ) the app crashes and closes.
The hexadecimal method is :
private void hexa_calc() {
int num = 0;
int num1 = Integer.parseInt(e_one.getText().toString().trim(),16);
int num2 =Integer.parseInt(e_two.getText().toString().trim(),16);
if (appKey1.operation.equals("+")) {
String value = Integer.toHexString(num1 + num2);
num = Integer.parseInt(value, 16);
t_result.setText(String.valueOf(Integer.toHexString(num)));
} else if (appKey1.operation.equals("-")) {
String value = Integer.toHexString(num1 - num2);
num = Integer.parseInt(value, 16);
t_result.setText(String.valueOf(Integer.toHexString(num)));
} else if (appKey1.operation.equals("X")) {
String value = Integer.toHexString(num1 * num2);
num = Integer.parseInt(value, 16);
t_result.setText(String.valueOf(Integer.toHexString(num)));
} else {
String value = Integer.toHexString(num1 / num2);
num = Integer.parseInt(value, 16);
t_result.setText(String.valueOf(Integer.toHexString(num)));
}
}
the second issue with the division operation is it gives the (result = 0 ) it's not like this 0.12324 without decimal after zero.
how can I solve this code?