Java Digit From toDigit(int n)

Here you can find the source of toDigit(int n)

Description

Returns the hex digit corresponding to a number n, from 0 to 15.

License

Open Source License

Declaration

public static char toDigit(int n) 

Method Source Code

//package com.java2s;
/*//from  ww  w  . ja va 2 s  .  c o m
 * Copyright (c) 1995-2008 Uwe B. Meding <uwe@uwemeding.com>
 *
 * This file is part of DTDC
 * This PCA software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DTDC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DTDC.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     * Returns the hex digit corresponding to a number n, from 0 to 15.
     */
    public static char toDigit(int n) {
        try {
            return hexDigits[n];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IllegalArgumentException(n + " is out of range for a hex digit");
        }
    }
}

Related

  1. toDigit(final char ch, final int index)
  2. toDigit(final char ch, final int index)
  3. toDigit(final int value)
  4. toDigit(int c)
  5. toDigit(int i)
  6. toDigit(int n)
  7. toDigiTime(int Zeit)