Java Binary Encode toBinaryFromHex(byte ch)

Here you can find the source of toBinaryFromHex(byte ch)

Description

Takes a ASCII digit in the range A-F0-9 and returns the corresponding integer/ordinal value.

License

Apache License

Parameter

Parameter Description
ch The hex digit.

Return

The converted hex value as a byte.

Declaration

public static byte toBinaryFromHex(byte ch) 

Method Source Code

//package com.java2s;
/*//from  www  . ja va 2  s .com
 * Copyright 2015 The RPC Project
 *
 * The RPC Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

public class Main {
    /**
     * Takes a ASCII digit in the range A-F0-9 and returns
     * the corresponding integer/ordinal value.
     * @param ch  The hex digit.
     * @return The converted hex value as a byte.
     */
    public static byte toBinaryFromHex(byte ch) {
        if (ch >= 'A' && ch <= 'F')
            return (byte) ((byte) 10 + (byte) (ch - 'A'));
        // else
        return (byte) (ch - '0');
    }
}

Related

  1. toBinaryArray(int input, int length)
  2. toBinaryArray(int integer, int size)
  3. toBinaryBoolean(boolean source)
  4. toBinaryChar(boolean bit)
  5. toBinaryClassName(String fileName)
  6. toBinaryID(final String id)
  7. toBinaryIeee754String(long decimal)
  8. toBinaryIntArray(byte[] bytes, int bitOffset, int bitCount)
  9. toBinaryName(String className)