Java Long to Hex long2HexString(StringBuilder buf, long value)

Here you can find the source of long2HexString(StringBuilder buf, long value)

Description

This method avoids the use on Long.toHexString, since this class may be used during the boot-phase when the Long class in not yet initialized.

License

Open Source License

Parameter

Parameter Description
buf a parameter
value a parameter

Declaration

private static void long2HexString(StringBuilder buf, long value) 

Method Source Code

//package com.java2s;
/*/* ww  w.  ja  v  a2  s . c  o  m*/
 * $Id$
 *
 * Copyright (C) 2003-2015 JNode.org
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library 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 Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; If not, write to the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

public class Main {
    /**
     * This method avoids the use on Long.toHexString, since this class may be used
     * during the boot-phase when the Long class in not yet initialized.
     *
     * @param buf
     * @param value
     */
    private static void long2HexString(StringBuilder buf, long value) {
        //      long rem = value & 0x0F;
        int rem = (int) (value & 0x0FL);
        long q = value >>> 4;
        if (q != 0) {
            long2HexString(buf, q);
        }

        if (rem < 10) {
            buf.append((char) ('0' + rem));
        } else {
            buf.append((char) ('A' + rem - 10));
        }
    }
}

Related

  1. Long2HexString(long h)
  2. long2hexString(long x)
  3. longToHex(long a)
  4. longToHex(long l)
  5. longToHex(long l, int length)
  6. longToHex(long num)