Answers for "java bytes to hex string"

2

java convert bytes to string

byte[] bytes = "hello".getBytes();
String s = new String(bytes, StandardCharsets.UTF_8);
Posted by: Guest on September-22-2020
1

String to hexadecimal in java

// String to hexadecimal in java
import java.util.Scanner;
public class StringToHexJava
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a string: ");
      String strInput = sc.next();
      StringBuffer sb = new StringBuffer();
      char[] chArray = strInput.toCharArray();
      for(int a = 0; a < chArray.length; a++)
      {
         String strHexadecimal = Integer.toHexString(chArray[a]);
         sb.append(strHexadecimal);
      }
      String strOutput = sb.toString();
      System.out.println(strOutput);
      sc.close();
   }
}
Posted by: Guest on February-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language