Character.getNumericValue();一个函数就搞定了,要得着那么复杂? 看看JavaDoc上怎么说的getNumericValuepublic static int getNumericValue(char ch) Returns the int value that the specified Unicode character represents. For example, the character '\u216C' (the roman numeral fifty) will return an int with a value of 50. The letters A-Z in their uppercase ('\u0041' through '\u005A'), lowercase ('\u0061' through '\u007A'), and full width variant ('\uFF21' through '\uFF3A' and '\uFF41' through '\uFF5A') forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values. If the character does not have a numeric value, then -1 is returned. If the character has a numeric value that cannot be represented as a nonnegative integer (for example, a fractional value), then -2 is returned. Parameters: ch - the character to be converted. Returns: the numeric value of the character, as a nonnegative int value; -2 if the character has a numeric value that is not a nonnegative integer; -1 if the character has no numeric value. Since: 1.1 See Also: forDigit(int, int), isDigit(char
{
byte[] b = "你".getBytes("unicode");
for(int i=0,iSize=b.length;i<iSize;i++)
System.out.println(Integer.toHexString(b[i]));
}
catch(UnsupportedEncodingException e)
{
}
如果你的字符来源于其他(文件、网络)那么就要在发送时候就指定是那种类型字符,在java再将他转换
难道要自己用native2ascii.exe去转换,然后再打开自己看吗不能写一个程序算出来,整整齐齐的打印在屏幕上面吗?
byte[] b = str.getBytes("UTF-16");
for(int i=0;i<b.length;i++)
System.out.println(Integer.toHexString(b[i]));
看看JavaDoc上怎么说的getNumericValuepublic static int getNumericValue(char ch)
Returns the int value that the specified Unicode character represents. For example, the character '\u216C' (the roman numeral fifty) will return an int with a value of 50. The letters A-Z in their uppercase ('\u0041' through '\u005A'), lowercase ('\u0061' through '\u007A'), and full width variant ('\uFF21' through '\uFF3A' and '\uFF41' through '\uFF5A') forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values. If the character does not have a numeric value, then -1 is returned. If the character has a numeric value that cannot be represented as a nonnegative integer (for example, a fractional value), then -2 is returned. Parameters:
ch - the character to be converted.
Returns:
the numeric value of the character, as a nonnegative int value; -2 if the character has a numeric value that is not a nonnegative integer; -1 if the character has no numeric value.
Since:
1.1
See Also:
forDigit(int, int), isDigit(char
char c='中';
System.out.println(Integer.toHexString(c));
你可以反编译class看看对不对
在class里面所有的字符串都被解析成unicode
String的话用str.toCharArray()得到char串
byte[] b = str.getBytes("UTF-16");
for(int i=0;i<b.length;i++)
System.out.println(Integer.toHexString(b[i]));
好像是有些问题的!
Character.getNumericValue();一个函数就搞定了,要得着那么复杂?
...
-----------------------------------
不能用