Java Long to Hex longToHexChars(long value, int length)

Here you can find the source of longToHexChars(long value, int length)

Description

Converts long value to sequence of hexadecimal character.

License

Apache License

Parameter

Parameter Description
value long value
length length of the target sequence

Return

hexadecimal characters

Declaration

public static char[] longToHexChars(long value, int length) 

Method Source Code

//package com.java2s;
/*/*w w  w  . j  a  v  a 2  s.  c  o m*/
 * Copyright (C) ExBin Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static final char[] UPPER_HEX_CODES = "0123456789ABCDEF"
            .toCharArray();

    /**
     * Converts long value to sequence of hexadecimal character. No range
     * checking.
     *
     * @param value long value
     * @param length length of the target sequence
     * @return hexadecimal characters
     */
    public static char[] longToHexChars(long value, int length) {
        char[] result = new char[length];
        longToHexChars(result, value, length);
        return result;
    }

    /**
     * Converts long value to sequence of hexadecimal character. No range
     * checking.
     *
     * @param target target char array
     * @param value long value
     * @param length length of the target sequence
     */
    public static void longToHexChars(char[] target, long value, int length) {
        for (int i = length - 1; i >= 0; i--) {
            target[i] = UPPER_HEX_CODES[(int) (value & 15)];
            value = value >> 4;
        }
    }
}

Related

  1. longToHex(long l, int length)
  2. longToHex(long num)
  3. longToHex(long val, char delim)
  4. longToHexBytes(final long v)
  5. longToHexBytes(long i)
  6. longToHexStr(long src, int len, int code)
  7. LongToHexString(final long value)
  8. longToHexString(long n, int digits)
  9. longToHexString(long num)