android convert EditText input string to its hex equivalent

Hello I would like my application to allow a user to input a number 1 to 16, press a button and then have the input number's hex equivalent shown on screen as a toast message and also store is hex in a single byte. Now i've most of it down and ready to go, its just i'm having problems with the input string to hex conversion. Would anyone be able to give me some help with the conversion?? I'm sure there must be an easy way of doing this?? For example if i input 1 it would display 0x31 on screen in a toast and 0x31 would be stored in a byte.

thanks code:

public class MainActivity extends Activity {

private static String toastMsg;
private static String input;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Button genButton = (Button) findViewById(R.id.btnGen);
    final EditText inputText = (EditText) findViewById(R.id.etxtInput);
    final TextView outputText = (TextView) findViewById(R.id.txtOutput);        

    genButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view){

            input = inputText.getText().toString();

            toastMsg = input;
            toast();
        }
    });


}



//-----TOAST---------------------------------//
public void toast() {

        Toast toast= Toast.makeText(getBaseContext(), toastMsg, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, -100);
        toast.show();

    }
}

Answers


You just want to change that one line:

toastMsg = input;

to this:

toastMsg = Integer.toHexString(Integer.parseInt(input));

Need Your Help

Replace entire row data and refresh

jquery datatables

I have generated a datatable based on a datasource like below. I would like to replace an element which is representing a row, then force the row to re-render with the new data.

Understanding "Bitwise-And (&)" and "Unary complement(~)" in c++

c++ c bitwise-operators logical-operators

I have some trouble understanding Bitwise-And and Unary Complement when both are used in this code snippet