Conversion of custom Chinese characters and ASCII values
Source: Internet
Author: User
Print the specified byte array in hexadecimal format to the console public static string tohexstring (int I) and return the string representation of an integer parameter in hexadecimal notation.
If the parameter is negative, the unsigned integer is 232. Otherwise, the value is equal to the parameter. Convert the value to an ASCII numeric string without leading 0 in hexadecimal notation (base 16. If the value of the unsigned number is zero, it is expressed with a zero character '0' ('\ u0030'); otherwise, the first character in the expression of the unsigned number size is not a zero character. Use the following characters as hexadecimal numbers:
0123456789 abcdef
These characters range from '\ u0030' to' \ u0039 'and from' \ u0061 'to' \ u0066 '. To obtain uppercase letters, you can call the string. touppercase () method in the result:
Integer. tohexstring (N). touppercase ()
Parameters:
I-The integer to be converted to a string.
Return Value:
The string representation of the unsigned integer represented by the hexadecimal (base 16) parameter.
// Convert the string to hexadecimal encoding.
Public static string tohexstring (string S)
{
String STR = "";
For (INT I = 0; I <S. Length (); I ++)
{
Int CH = (INT) S. charat (I );
String S4 = integer. tohexstring (CH );
STR = STR + S4;
}
Return STR;
}
// Convert the hexadecimal encoded string
Public static string tostringhex (string S)
{
Byte [] bakeyword = new byte [S. Length ()/2];
For (INT I = 0; I <bakeyword. length; I ++)
{
Try
{
Bakeyword [I] = (byte) (0xff & integer. parseint (S. substring (I * 2, I * 2 + 2), 16 ));
}
Catch (exception E)
{
E. printstacktrace ();
}
}
Try
{
S = new string (bakeyword, "UTF-8"); // UTF-16le: Not
}
Catch (exception E1)
{
E1.printstacktrace ();
}
Return S;
}
// Convert the hexadecimal encoded string
Public static string tostringhex (string S)
{
Byte [] bakeyword = new byte [S. Length ()/2];
For (INT I = 0; I <bakeyword. length; I ++)
{
Try
{
Bakeyword [I] = (byte) (0xff & integer. parseint (S. substring (I * 2, I * 2 + 2), 16 ));
}
Catch (exception E)
{
E. printstacktrace ();
}
}
Try
{
S = new string (bakeyword, "UTF-8"); // UTF-16le: Not
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.