Tag:throw print Implementation final ring nal %x throws git
public class Hexutil {private static final string[] Digits_upper = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}; public static void Main (string[] args) throws Decoderexception {System.out.println (ToHex1 ((byte)-128)); System.out.println (ToHex2 ((byte)-128)); System.out.println (ToHex3 ((byte)-128)); System.out.println (ToHex4 ((byte)-128)); } public static String ToHex1 (byte value) {int high = (value & 0xF0) >>> 4; int low = value & 0x0F; return Digits_upper[high] + Digits_upper[low]; } public static String ToHex2 (byte value) {int high = (value >>> 4) & 0x0F; int low = value & 0x0F; return Digits_upper[high] + Digits_upper[low]; } public static String toHex3 (byte value) {int tmp = value; if (value < 0) {TMP = value + 256; } int high = TMP/16; int low = tmp% 16; return Digits_upper[high] + Digits_upper[low]; } public static String toHex4 (byte value) {return String.Format ("%x", value); }}
Reference
Complement
Several implementations of converting to 16 in Java