Java Hex Calculate toHexChar(int digitValue)

Here you can find the source of toHexChar(int digitValue)

Description

Convert a digital value to hex

License

Open Source License

Parameter

Parameter Description
digitValue a parameter

Return

Character representing the given integer

Declaration

public static char toHexChar(int digitValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 MadRobot./*from w ww . j av a 2 s.co m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Convert a digital value to hex
     * 
     * @param digitValue
     * @return Character representing the given integer
     */
    public static char toHexChar(int digitValue) {
        if (digitValue < 10) {
            // Convert value 0-9 to char 0-9 hex char
            return (char) ('0' + digitValue);
        } else {
            // Convert value 10-15 to A-F hex char
            return (char) ('A' + (digitValue - 10));
        }
    }
}

Related

  1. toHexChar(byte[] bArray)
  2. toHexChar(char ch, StringBuffer sb)
  3. toHexChar(int b)
  4. toHexChar(int digit)
  5. toHexChar(int digitValue)
  6. toHexChar(int i)
  7. toHexChar(int i)
  8. toHexChar(int i)
  9. toHexChar(int nibble)