Convert an integer into a hex-string. - Java 2D Graphics

Java examples for 2D Graphics:Color HEX

Description

Convert an integer into a hex-string.

Demo Code

/**//www  .ja va  2  s . co  m
 * This file is part of OSMNavigation by Marcus Wolschon <a href="mailto:Marcus@Wolscon.biz">Marcus@Wolscon.biz</a>.
 * You can purchase support for a sensible hourly rate or
 * a commercial license of this file (unless modified by others) by contacting him directly.
 *
 *  OSMNavigation 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.
 *
 *  LibOSM 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 OSMNavigation.  If not, see <http://www.gnu.org/licenses/>.
 *
 ***********************************
 * Editing this file:
 *  -For consistent code-quality this file should be checked with the
 *   checkstyle-ruleset enclosed in this project.
 *  -After the design of this file has settled it should get it's own
 *   JUnit-Test that shall be executed regularly. It is best to write
 *   the test-case BEFORE writing this class and to run it on every build
 *   as a regression-test.
 */
//package com.java2s;

public class Main {
    /**
     * 16.
     */
    private static final int HEX = 16;

    /**
     * Convert an integer into a hex-string.
     * @param i the integer
     * @return the hex-value
     */
    private static String int2hex(final int i) {
        String s = Integer.toHexString(i / HEX)
                + Integer.toHexString(i % HEX);
        return s.toUpperCase();
    }
}

Related Tutorials