In Java, is there a simple method to convert the format of a given string? For example, I have the string “test22”. I’d like the binary value and hex value. As well as possibly the ascii values of each character?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My solution would be to take the String, convert it to a char array, and then convert the integer values of the char array into binary or hex through the Integer.toBinaryString() or Integer.toHexString() or Integer.toOctalString() if you would like.
just replace binary string with hex and the function will do the same thing
Also to get the ASCII values of the String
int value = (int)string.charAt(i);will get the ASCII value.I added a space just for formatting, not sure how you needed it formatted, and this is just a simple implementation.