Java Hex Format formatText(String value, boolean showAsHexFlag)

Here you can find the source of formatText(String value, boolean showAsHexFlag)

Description

reads an String representation of an Integer, if the showAsHexFlag is set, it converts it to hex to a hex string representation for display

License

Open Source License

Parameter

Parameter Description
value the string to format
showAsHexFlag the boolean flag that determines wether to display a number as hex

Return

a String to be displayed in the text field

Declaration

public static String formatText(String value, boolean showAsHexFlag) 

Method Source Code

//package com.java2s;
// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which 

public class Main {
    /**//from ww w . j ava2  s. c  om
     * reads an String representation of an Integer, if the showAsHexFlag is set, it converts it to hex
     * to a hex string representation for display
     * @param value the string to format
     * @param showAsHexFlag the boolean flag that determines wether to display a number as hex
     * @return a String to be displayed in the text field
     */
    public static String formatText(String value, boolean showAsHexFlag) {
        try {
            int numberToCheck = Integer.parseInt(value);

            if (showAsHexFlag) {
                StringBuffer buffer = new StringBuffer();
                buffer.append("0x");
                buffer.append(Integer.toHexString(numberToCheck));

                value = buffer.toString();
            }
        } catch (NumberFormatException nfe) {
        }

        return value;
    }
}

Related

  1. formatHexReversed(String original, int length)
  2. formatHexStr(int width, String hexStr)
  3. formatHexString(final String input, final int charsPerLine)
  4. formatHexToString(byte[] bytes)
  5. formatInHex(byte[] bySrc, int nLineLen)
  6. formatToHex(int rgb)