Here you can find the source of toHexString(final long num, final char paddingChar, int min, int max)
Internal use.
Parameter | Description |
---|---|
num | the long number to convert. |
paddingChar | the character to use for padding. |
min | the minimum length of the resulting String. |
max | the maximum length of the resulting String. |
private static String toHexString(final long num, final char paddingChar, int min, int max)
//package com.java2s; /*//w w w . jav a2s .c o m * This file is part of SerialPundit. * * Copyright (C) 2014-2016, Rishi Gupta. All rights reserved. * * The SerialPundit is DUAL LICENSED. It is made available under the terms of the GNU Affero * General Public License (AGPL) v3.0 for non-commercial use and under the terms of a commercial * license for commercial use of this software. * * The SerialPundit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ public class Main { /** * <p>Internal use.</p> * * @param num the long number to convert. * @param paddingChar the character to use for padding. * @param min the minimum length of the resulting String. * @param max the maximum length of the resulting String. */ private static String toHexString(final long num, final char paddingChar, int min, int max) { /* Formats a long number into the specified length hex String. This is identical to Long.toHexString() * except that it pads (with 0's), or truncates, to the specified size. If max < min, the * functionality is exactly as Long.toHexString(). */ StringBuffer sb = new StringBuffer(Long.toHexString(num)); if (max < min) { return sb.toString(); } while (sb.length() < max) { sb.insert(0, paddingChar); } return sb.substring(0, min); } }