JBBPUtils { public static String ulong2str(final long ulongValue, final int radix, final char[] charBuffer) { if (radix < 2 || radix > 36) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } if (ulongValue == 0) { return "0"; } else { final String result; if (ulongValue > 0) { result = Long.toString(ulongValue, radix).toUpperCase(Locale.ENGLISH); } else { final char[] buffer = charBuffer == null || charBuffer.length < 64 ? new char[64] : charBuffer; int pos = buffer.length; long topPart = ulongValue >>> 32; long bottomPart = (ulongValue & 0xFFFFFFFFL) + ((topPart % radix) << 32); topPart /= radix; while ((bottomPart | topPart) > 0) { final int val = (int) (bottomPart % radix); buffer[--pos] = (char) (val < 10 ? '0' + val : 'A' + val - 10); bottomPart = (bottomPart / radix) + ((topPart % radix) << 32); topPart /= radix; } result = new String(buffer, pos, buffer.length - pos); } return result; } } private  JBBPUtils(); static byte[] strToUtf8(final String str); static String utf8ToStr(final byte[] array); static boolean isNumber(final String num); static byte[] packInt(final int value); static int packInt(final byte[] array, final JBBPIntCounter position, final int value); static int unpackInt(final byte[] array, final JBBPIntCounter position); static String array2hex(final byte[] array); static String array2bin(final byte[] array); static String array2oct(final byte[] array); static String byteArray2String(final byte[] array, final String prefix, final String delimiter, final boolean brackets, final int radix); static byte reverseBitsInByte(final byte value); static byte reverseBitsInByte(final JBBPBitNumber bitNumber, final byte value); static String bin2str(final byte[] values); static String bin2str(final byte[] values, final boolean separateBytes); static String bin2str(final byte[] values, final JBBPBitOrder bitOrder, final boolean separateBytes); static List<JBBPAbstractField> fieldsAsList(final JBBPAbstractField... fields); static byte[] str2bin(final String values); static byte[] str2bin(final String values, final JBBPBitOrder bitOrder); static String[] splitString(final String str, final char splitChar); static void assertNotNull(final Object object, final String message); static String int2msg(final int number); static String normalizeFieldNameOrPath(final String nameOrPath); static void closeQuietly(final Closeable closeable); static byte[] str2UnicodeByteArray(final JBBPByteOrder byteOrder, final String str); static byte[] reverseArray(final byte[] nullableArrayToBeInverted); static byte[] splitInteger(final int value, final boolean valueInLittleEndian, final byte[] buffer); static byte[] splitLong(final long value, final boolean valueInLittleEndian, final byte[] buffer); static byte[] concat(final byte[]... arrays); static long reverseByteOrder(long value, int numOfLowerBytesToInvert); static String double2str(final double doubleValue, final int radix); static String float2str(final float floatValue, final int radix); static String ulong2str(final long ulongValue, final int radix, final char[] charBuffer); static String ensureMinTextLength(final String text, final int neededLen, final char ch, final int mode); static String removeLeadingZeros(final String str); static String removeTrailingZeros(final String str); static boolean arrayStartsWith(final byte[] array, final byte[] str); static boolean arrayEndsWith(final byte[] array, final byte[] str); static int makeMask(final int value); static boolean equals(final Object o1, final Object o2); static final String[] ARRAY_STRING_EMPTY; static final JBBPAbstractField[] ARRAY_FIELD_EMPTY; }
@Test public void testULong2Str_UnsignedHex() throws Exception { assertEquals("12345678ABCD", JBBPUtils.ulong2str(0x12345678ABCDL, 16, null)); assertEquals("7FFFFFFFFFFFFFFF", JBBPUtils.ulong2str(0x7FFFFFFFFFFFFFFFL, 16, null)); assertEquals("8000000000000000", JBBPUtils.ulong2str(0x8000000000000000L, 16, null)); assertEquals("8FFFFFFFFFFFFFFF", JBBPUtils.ulong2str(0x8FFFFFFFFFFFFFFFL, 16, null)); assertEquals("8100000000000000", JBBPUtils.ulong2str(0x8100000000000000L, 16, null)); assertEquals("F23418824AB12342", JBBPUtils.ulong2str(0xF23418824AB12342L, 16, null)); }
@Test public void testULong2Str_UnsignedDec() throws Exception { assertEquals("20015998348237", JBBPUtils.ulong2str(0x12345678ABCDL, 10, null)); assertEquals("9223372036854775807", JBBPUtils.ulong2str(9223372036854775807L, 10, null)); assertEquals("9223372036853827875", JBBPUtils.ulong2str(0x7FFFFFFFFFF18923L, 10, null)); assertEquals("9223372036854775808", JBBPUtils.ulong2str(0x8000000000000000L, 10, null)); assertEquals("10376293541461622783", JBBPUtils.ulong2str(0x8FFFFFFFFFFFFFFFL, 10, null)); assertEquals("9295429630892703744", JBBPUtils.ulong2str(0x8100000000000000L, 10, null)); assertEquals("17452601403845452610", JBBPUtils.ulong2str(0xF23418824AB12342L, 10, null)); }