Android Hex String Create hexCharToInt(char c)

Here you can find the source of hexCharToInt(char c)

Description

hex Char To Int

License

Apache License

Declaration

static int hexCharToInt(char c) 

Method Source Code

//package com.java2s;
/*//from w  w w. j  av a2 s . c o  m
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed 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 {
    static int hexCharToInt(char c) {
        if (c >= '0' && c <= '9')
            return (c - '0');
        if (c >= 'A' && c <= 'F')
            return (c - 'A' + 10);
        if (c >= 'a' && c <= 'f')
            return (c - 'a' + 10);

        throw new RuntimeException("invalid hex char '" + c + "'");
    }
}

Related

  1. byte2hex(byte[] bytes)
  2. bytesToHex(byte[] bytes)
  3. encodeHex(byte[] bytes)
  4. encodeHex(byte[] pData)
  5. hex(int value, int digits)
  6. hexDecode(String str, byte[] ba, int len)
  7. hexEncode(byte[] aInput)
  8. hexify(byte bytes[])
  9. toHex(String str)