Here you can find the source of toHexDigit(int value, int digitPosition)
Parameter | Description |
---|---|
value | base-10 integer to convert |
digitPosition | designated hex digit position |
public static String toHexDigit(int value, int digitPosition)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j a v a 2s.c om*/ * Converts a base-ten integer to a hexadecimal value at a particular digit. * @param value base-10 integer to convert * @param digitPosition designated hex digit position * @return String representation of the hex digit */ public static String toHexDigit(int value, int digitPosition) { int digitValue = (value >>> (digitPosition * 4)) & 0xf; return Integer.toHexString(digitValue); } /** * Returns a base-10 integer as a hexadecimal number in String. * @param value base-10 integer to convert * @param numDigits number of hex digits to display * @return String representation of the hex number */ public static String toHexString(int value, int numDigits) { StringBuilder result = new StringBuilder(); for (int i = (numDigits - 1); i >= 0; i--) { String digit = toHexDigit(value, i); result.append(digit); } return result.toString().toUpperCase(); } }