get Two Digit Hex String - Java java.lang

Java examples for java.lang:Hex

Description

get Two Digit Hex String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int integer = 2;
        System.out.println(getTwoDigitHexString(integer));
    }/*from   w w w . jav  a 2s . c o m*/

    private static String getTwoDigitHexString(int integer) {

        StringBuilder sb = new StringBuilder();
        sb.append(Integer.toHexString(integer));
        if (sb.length() < 2) {
            sb.insert(0, '0'); // pad with leading zero if needed
        }

        return sb.toString();

    }
}

Related Tutorials