Home  >  Article  >  Java  >  How do we convert hexadecimal value to bytes in Java?

How do we convert hexadecimal value to bytes in Java?

WBOY
WBOYforward
2023-09-08 15:37:021315browse

How do we convert hexadecimal value to bytes in Java?

A Byte class is a subclass of the Number class, which can wrap the value of the original type byte in an object. An object of class Byte contains a single field of type byte. Important methods of the Byte class include byteValue(), compare(), compareTo(), decode(), parseByte (), valueOf(), etc. We can use the Byte class method decode().byteValue() to convert the hexadecimal value to byte. The Chinese translation of

Grammar

<strong>public final class Byte extends Number implements Comparable<Byte></strong>

Example

is:

Example

public class ConvertHexaDecimalToByte {
   public static void main(String args[]) {
      byte b = Byte.decode("0x0a").byteValue(); <strong>// convert hexadecimal value to byte.</strong>
      System.out.println(b);
   }
}

Output

10

The above is the detailed content of How do we convert hexadecimal value to bytes in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete