Java Long to String longToString(long n)

Here you can find the source of longToString(long n)

Description

Returns a string of 16 hexadecimal digits (most significant digit first) corresponding to the long n, which is treated as unsigned.

License

Open Source License

Declaration

public static String longToString(long n) 

Method Source Code

//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);
    }
}

Related

  1. LongToString(Long l, int length)
  2. longToString(long li)
  3. longToString(long longV)
  4. longToString(long longValue)
  5. longToString(long longValue, boolean noCase)
  6. LongToString(long number, boolean bcdFlag, int bufferSize)
  7. longToString(long val)
  8. longToString(long value)
  9. longToString(long value)