Java Hex Calculate toHex(int h, int minDigit)

Here you can find the source of toHex(int h, int minDigit)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(int h, int minDigit) 

Method Source Code

//package com.java2s;
/*// ww w .j  a v  a 2 s. c o m
 *    Qizx/open 4.1
 *
 * This code is the open-source version of Qizx.
 * Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
 *
 * The contents of this file are subject to the Mozilla Public License 
 *  Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 *  for the specific language governing rights and limitations under the
 *  License.
 *
 * The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
 *
 */

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

    public static String toHex(int h, int minDigit) {
        char[] digits = new char[8];
        int d = 7;
        do {
            digits[d--] = hexDigits[h & 0xf];
            h >>>= 4;
            --minDigit;
        } while (h != 0 || minDigit > 0);
        return new String(digits, d + 1, 7 - d);
    }
}

Related

  1. toHex(final String input)
  2. toHex(int ch)
  3. toHex(int ch)
  4. toHex(int color)
  5. toHex(int decimalDigit)
  6. toHex(int i)
  7. toHex(int i)
  8. toHex(int i)
  9. toHex(int i, String $default)