Convert hexadecimal string (hex) to a binary string

后端 未结 7 2034
孤独总比滥情好
孤独总比滥情好 2020-11-30 07:31

I found the following way hex to binary conversion:

String binAddr = Integer.toBinaryString(Integer.parseInt(hexAddr, 16)); 

While this app

7条回答
  •  囚心锁ツ
    2020-11-30 08:19

    Integer.parseInt(hex,16);    
    System.out.print(Integer.toBinaryString(hex));
    

    Parse hex(String) to integer with base 16 then convert it to Binary String using toBinaryString(int) method

    example

    int num = (Integer.parseInt("A2B", 16));
    System.out.print(Integer.toBinaryString(num));
    

    Will Print

    101000101011
    

    Max Hex vakue Handled by int is FFFFFFF

    i.e. if FFFFFFF0 is passed ti will give error

提交回复
热议问题