Converting Hexadecimal String to Decimal Integer

后端 未结 14 1987
感动是毒
感动是毒 2020-12-09 16:02

I wrote some code to convert my hexadecimal display string to decimal integer. However, when input is something like 100a or 625b( something with letter) I got an error like

14条回答
  •  盖世英雄少女心
    2020-12-09 16:39

    This is a little library that should help you with hexadecimals in Java: https://github.com/PatrykSitko/HEX4J

    It can convert from and to hexadecimals. It supports:

    • byte
    • boolean
    • char
    • char[]
    • String
    • short
    • int
    • long
    • float
    • double (signed and unsigned)

    With it, you can convert your String to hexadecimal and the hexadecimal to a float/double.

    Example:

    String hexValue = HEX4J.Hexadecimal.from.String("Hello World");
    double doubleValue = HEX4J.Hexadecimal.to.Double(hexValue);
    

提交回复
热议问题