How to Convert string to HexaDecimal?
18,899
This should be
Integer.toHexString(Integer.parseInt(String));
Ref : Convert to/from hexadecimal
Author by
RajaReddy PolamReddy
I love programming. I mostly code in "Android", "ActionScript", "Adobe Flash", Adobe AS3, iOS, Objective-C . My App.. Image Crop Current applications BingoBash and Slots Bash SOreadytohelp
Updated on June 05, 2022Comments
-
RajaReddy PolamReddy almost 2 years
I have a string like this:
"12"
And I need to convert it to a hex value like this:
0x12
I have a byte array like this
// 00 20 22 80 08 24 pi nn ff ff ff ff ff byte VerifyingAPDU[] = { (byte)0x00,(byte)0x20,(byte)0x00,(byte)0x80,(byte)0x08,(byte)0x24, (byte)0x12,(byte)0x34, //pi nn (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }; Now i want to replace pi nn with user entered value in Eidter (EditText). how to do this ?
For example user entered 1111 in editer i have to replace Ox12 --> 0x11 and 0x34-->0x11.
-
RajaReddy PolamReddy almost 11 yearsI tried like that.. see if i have String a = "12"; i want to get create hex value for that is
0x12
. how to do this. -
Simon almost 11 years@RajaReddyPolamReddy, er,
"0x" + Integer.toHexString(Integer.parseInt(String));
-
Pankaj Kumar almost 11 yearsI agreed with @Simon. You can do like that. Is there any problem
-
RajaReddy PolamReddy almost 11 years@PankajKumar i will check like this, let u know the result.
-
RajaReddy PolamReddy almost 11 yearsIts giving me the HexaDecimal Value upto that it's ok. for my requirement i want to do like this. look at the edited Question.
-
Pankaj Kumar almost 11 years@RajaReddyPolamReddy ahhhh your updated question is completely different from asked.. And you unaccepted the answer... :)
-
RajaReddy PolamReddy almost 11 yearsSry for that. Please can u tell me the solution for this. i am struck at that.please...
-
RajaReddy PolamReddy almost 11 yearsFor converting String to Hex this code working well..
-
Pankaj Kumar almost 11 years
int inputInteger = Integer.valueOf(edit_text_value); String firstHex = "0x" + Integer.toHexString(inputInteger/ 100); String secondHex = "0x" + Integer.toHexString(inputInteger % 100);
Use these codes.. here I assumed that length of edittext is set to 4. -
RajaReddy PolamReddy almost 11 yearsActually, if i enter 1234 was the pin i have to get 0x12 and 0x34, but this code gives me like this 0xc and 0x22..
-
Pankaj Kumar almost 11 yearsyes I am right till you are asking about HEX. But again you are saying another thing if 12 should be 0X12 then this is not a HEX of 12. You can simply add '0X' to given string..
-
RajaReddy PolamReddy almost 11 years@PankajKumar i tried to convert String to byte, i am unable to convert it. can u help me on this typecast..please.