Here you can find the source of longToString(long n)
public static String longToString(long n)
//package com.java2s; /*/*ww w .ja v a2 s. co m*/ * Copyright (c) 1995-2008 Uwe B. Meding <uwe@uwemeding.com> * * This file is part of DTDC * This PCA software is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DTDC 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. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DTDC. If not, see <http://www.gnu.org/licenses/>. */ public class Main { private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Returns a string of 16 hexadecimal digits (most significant digit first) * corresponding to the long n, which is treated as unsigned. */ public static String longToString(long n) { char[] buf = new char[16]; for (int i = 15; i >= 0; i--) { buf[i] = hexDigits[(int) n & 0x0F]; n >>>= 4; } return new String(buf); } }