开发者

Convert character value to hexa in java

开发者 https://www.devze.com 2023-02-07 17:40 出处:网络
I have method to covert character to haxa like private static String convert(char str) { StringBuffer ostr = new StringBuffer();

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消