Here you can find the source of charToHex(char c)
Parameter | Description |
---|---|
c | Character to process. |
static public String charToHex(char c)
//package com.java2s; /*-------------------------------------------------------------------------------- Copyright (C) 2002, 2004 ISOGEN International http://www.isogen.com//from w w w . j a va 2 s. c om This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation. This program 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. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --------------------------------------------------------------------------------*/ public class Main { /** * Returns hex String representation of char c, that is, the hex * digits of the Unicode code point for the character. * @param c Character to process. * @return Hex string of the character's code point. */ static public String charToHex(char c) { // Returns hex String representation of char c byte hi = (byte) (c >>> 8); byte lo = (byte) (c & 0xff); return byteToHex(hi) + byteToHex(lo); } /** * Converts a byte to the string representation of its hex value. * @param b The byte to process. * @return A string consisting of hex digits. */ static public String byteToHex(byte b) { // Returns hex String representation of byte b char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] }; return new String(array); } }