Java Integer to Hex intToHexChars(int n)

Here you can find the source of intToHexChars(int n)

Description

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

License

Open Source License

Declaration

private static char[] intToHexChars(int n) 

Method Source Code

//package com.java2s;
/**// w w w  .  ja  va2s .c  o m
 * Copyright 2001-2014 CryptoHeaven Corp. All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of CryptoHeaven Corp. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with CryptoHeaven Corp.
 */

public class Main {
    /** data for hexadecimal visualisation. */
    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
    * Returns a string of 8 hexadecimal digits (most significant
    * digit first) corresponding to the integer <i>n</i>, which is
    * treated as unsigned.
    */
    private static char[] intToHexChars(int n) {
        char[] buf = new char[8];
        for (int i = 7; i >= 0; i--) {
            buf[i] = HEX_DIGITS[n & 0x0F];
            n >>>= 4;
        }
        return buf;
    }
}

Related

  1. intToHex(int val, StringBuffer sb)
  2. intTohex2(int value)
  3. intToHex8(int value)
  4. intToHexBytes(int i)
  5. intToHexChar(int i)
  6. intToHexLE(int val)
  7. intToHexStr(int i, int len)
  8. intToHexStr(int src, int len, int code)
  9. IntToHexString(final int value)