Here you can find the source of toHex4(int value)
public static String toHex4(int value)
//package com.java2s; /*/* w w w .j a v a2 s .c o m*/ HexUtils.java (c) 2010-2013 Edward Swartz All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { public static String toHex4(int value) { if (value < 0) value &= 0xffff; return padAddress(Integer.toHexString(value & 0x7fffffff).toUpperCase()); } /** * @param string * @return */ public static String padAddress(String string) { final byte[] zeroes = { '0', '0', '0', '0' }; int len = 4 - string.length(); if (len > 0) { return new String(zeroes, 0, len) + string; } else { return string; } } }