 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert hex string to byte Array in Java?
We can convert a hex string to byte array in Java by first converting the hexadecimal number to integer value using the parseInt() method of the Integer class in java. This will return an integer value which will be the decimal conversion of hexadecimal value. We will then use the toByteArray() method of BigInteger class that will return a byte array.
Example
import java.math.BigInteger; public class Demo {    public static void main(String args[]) {       String str = "1D08A";       int it = Integer.parseInt(str, 16);       System.out.println("Hexadecimal String " + str);       BigInteger bigInt = BigInteger.valueOf(it);       byte[] bytearray = (bigInt.toByteArray());       System.out.print("Byte Array : ");       for(int i = 0; i < bytearray.length; i++)       System.out.print(bytearray[i]+ "\t");    } }  Output
Hexadecimal String 1D08A Byte Array : 1 -48 -118
Advertisements
 