Here you can find the source of toHex(final int i)
public static String toHex(final int i)
//package com.java2s; /*/*from w ww . j a v a 2s . c o m*/ * Copyright 2004-2011 the Seasar Foundation and the Others. * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ public class Main { public static String toHex(final byte[] bytes) { if (bytes == null) { return ""; } StringBuffer sb = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; ++i) { appendHex(sb, bytes[i]); } return sb.toString(); } public static String toHex(final int i) { StringBuffer buf = new StringBuffer(); appendHex(buf, i); return buf.toString(); } public static void appendHex(final StringBuffer buf, final byte i) { buf.append(Character.forDigit((i & 0xf0) >> 4, 16)); buf.append(Character.forDigit((i & 0x0f), 16)); } public static void appendHex(final StringBuffer buf, final int i) { buf.append(Integer.toHexString((i >> 24) & 0xff)); buf.append(Integer.toHexString((i >> 16) & 0xff)); buf.append(Integer.toHexString((i >> 8) & 0xff)); buf.append(Integer.toHexString(i & 0xff)); } }