Advertisement
FuskedLLCC

Untitled

Mar 10th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class HelloWorld{
  2.  
  3. public static void main(String []args){
  4. System.out.println(str2Hex("Hello World"));
  5. }
  6.  
  7. public static String HexToString(String hex){
  8.  
  9. StringBuilder finalString = new StringBuilder();
  10. StringBuilder tempString = new StringBuilder();
  11.  
  12. for( int i=0; i<hex.length()-1; i+=2 ){
  13. String output = hex.substring(i, (i + 2));
  14. int decimal = Integer.parseInt(output, 16);
  15. finalString.append((char)decimal);
  16. tempString.append(decimal);
  17. }
  18. return finalString.toString();
  19. }
  20.  
  21.  
  22. public static String str2Hex(String text ){
  23.  
  24. char[] chars = text.toCharArray();
  25. StringBuffer hex = new StringBuffer();
  26. for (int i = 0; i < chars.length; i++) {
  27. hex.append(Integer.toHexString((int) chars[i]));
  28. }
  29. String hexText = hex.toString();
  30.  
  31. return hexText;
  32. }
  33.  
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement