Convert character value to hexa in java
I have method to covert character to haxa like
private static String convert(char str)
{
StringBuffer ostr = new StringBuffer();
String hex = Integer.toHexString(str & 0xFFFF);
for(int j=0; j<4-hex.length(); j++)
ostr.append("0");
ostr.ap开发者_开发技巧pend(hex.toUpperCase());
return (new String(ostr));
}
Its work fine for window but create problem for linux. Can any one suggest me how to do same thing in linux ?
You may try, e.g.:
String.format("%1$04x", ('c' & 0xFFFF))
Check the documentation of java.lang.String
for more details.
Cheers!
精彩评论