Java Long to Hex longtoHexString(long wert, int bits)

Here you can find the source of longtoHexString(long wert, int bits)

Description

longto Hex String

License

Open Source License

Declaration

public static String longtoHexString(long wert, int bits) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 EmbSysRegView//from   ww  w  . java2s .c o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     ravenclaw78 - initial API and implementation
 *******************************************************************************/

public class Main {
    public static String longtoHexString(long wert, int bits) {

        int hexdigits = bits / 4;
        if (bits % 4 != 0)
            hexdigits++;

        StringBuilder hex = new StringBuilder();
        hex.append("0x");
        String x = Long.toHexString(wert);
        int missingLen = hexdigits - x.length();
        for (int i = 0; i < missingLen; i++)
            hex.append('0');
        hex.append(x.toUpperCase());
        return hex.toString();
    }
}

Related

  1. longToHexStr(long src, int len, int code)
  2. LongToHexString(final long value)
  3. longToHexString(long n, int digits)
  4. longToHexString(long num)
  5. longToHexString(long number)
  6. longToHexval(long l)