Java Hex to Byte convertHexCharacterToHalfByte(char character)

Here you can find the source of convertHexCharacterToHalfByte(char character)

Description

convert Hex Character To Half Byte

License

Open Source License

Declaration

static byte convertHexCharacterToHalfByte(char character) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static byte convertHexCharacterToHalfByte(char character) {
        if ((character >= '0') && (character <= '9')) {
            return (byte) (character - '0');
        } else if ((character >= 'a') && (character <= 'f')) {
            return (byte) (character - 'a' + 10);
        } else if ((character >= 'A') && (character <= 'F')) {
            return (byte) (character - 'A' + 10);
        } else {/*from   w  ww  .  j a v  a 2s  .  c  o  m*/
            throw new IllegalArgumentException("'" + character + "' is an illegal character in HEX code!");
        }
    }
}

Related

  1. convertHexDigit(byte b)
  2. convertHexDigit(byte b)
  3. convertHexDigit(byte b)
  4. convertHexDigit(byte b)