how to convert a char from alphabetical character to hexadecimal number in java

前端 未结 3 1759
臣服心动
臣服心动 2020-12-09 08:59

how to convert a char from alphabetical character to hexadecimal number in java a if any one have any built-in method in java that does the job or if you have your own metho

相关标签:
3条回答
  • 2020-12-09 09:48

    Use the apache commons codec library

    Specifically: http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Hex.html

    0 讨论(0)
  • 2020-12-09 09:49

    You could use:

    Integer.toHexString((int) 'a');
    Integer.toBinaryString((int) 'b');
    

    Update: hex -> binary conversion:

    Integer.toBinaryString(Integer.parseInt("fa", 16))
    
    0 讨论(0)
  • 2020-12-09 09:56

    You can convert from char to hex string.

    char ch = 
    String hex = String.format("%04x", (int) ch);
    

    To read hex and convert to binary you can do

    int num = Integer.parseInt(text, 16);
    String bin = Integer.toString(num, 2);
    
    0 讨论(0)
提交回复
热议问题