Computer >> 컴퓨터 >  >> 프로그램 작성 >> Java

Java에서 16진수 값을 바이트로 어떻게 변환할 수 있습니까?

<시간/>

바이트 class는 Number 의 하위 클래스입니다. 클래스이며 객체에서 기본 유형 바이트의 값을 래핑할 수 있습니다. Byte 유형의 개체는 유형이 byte인 단일 필드를 포함합니다. . Byte 클래스의 중요한 메소드는 byteValue()입니다. , compare(), compareTo(), decode(), parseByte(), valueOf() 등. decode().byteValue() 메서드를 사용하여 16진수 값을 바이트로 변환할 수 있습니다. 바이트 의 수업.

구문

public final class Byte extends Number implements Comparable<Byte>

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

출력

10