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

How do we convert hexadecimal value to bytes in Java?

WBOY
Release: 2023-09-08 15:37:02
forward
1322 people have browsed it

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>
Copy after login

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);
   }
}
Copy after login

Output

10
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template