Here you can find the source of toHex(int n, Boolean bigEndian)
Parameter | Description |
---|---|
n | The int value to output as hex |
bigEndian | Flag to output the int as big or little endian |
public static String toHex(int n, Boolean bigEndian)
//package com.java2s; public class Main { /** String for quick lookup of a hex character based on index */ private static String hexChars = "0123456789abcdef"; /**/* ww w. ja v a 2 s.c om*/ * Outputs the hex value of a int, allowing the developer to specify * the endinaness in the process. Hex output is lowercase. * * @param n The int value to output as hex * @param bigEndian Flag to output the int as big or little endian * @return A string of length 8 corresponding to the * hex representation of n ( minus the leading "0x" ) * @langversion ActionScript 3.0 * @playerversion Flash 9.0 * @tiptext */ public static String toHex(int n, Boolean bigEndian) { String s = ""; if (bigEndian) { for (int i = 0; i < 4; i++) { s += hexChars.charAt((n >> ((3 - i) * 8 + 4)) & 0xF) + hexChars.charAt((n >> ((3 - i) * 8)) & 0xF); } } else { for (int x = 0; x < 4; x++) { s += hexChars.charAt((n >> (x * 8 + 4)) & 0xF) + hexChars.charAt((n >> (x * 8)) & 0xF); } } return s; } }