Java Hex Calculate toHexString(long value, int digits)

Here you can find the source of toHexString(long value, int digits)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(long value, int digits) 

Method Source Code

//package com.java2s;
/*/*from  w w  w  . j a  v a  2  s . co  m*/
 * PortUtil.cs
 * Copyright ? 2009-2011 kbinani
 *
 * This file is part of org.kbinani.
 *
 * org.kbinani is free software; you can redistribute it and/or
 * modify it under the terms of the BSD License.
 *
 * org.kbinani 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.
 */

public class Main {
    public static String toHexString(long value, int digits) {
        String ret = toHexString(value);
        int add = digits - getStringLength(ret);

        for (int i = 0; i < add; i++) {
            ret = "0" + ret;
        }

        return ret;
    }

    public static String toHexString(long value) {
        return Long.toHexString(value);
    }

    public static int getStringLength(String s) {
        if (s == null) {
            return 0;
        } else {
            return s.length();
        }
    }
}

Related

  1. toHexString(long l)
  2. toHexString(long l)
  3. toHexString(long l)
  4. toHexString(long l)
  5. toHexString(long value, int digits)
  6. ToHexString(long[] data)
  7. toHexString(String data)
  8. toHexString(String input)
  9. toHexString(String s)