I believe FFFFFFFF
is -1
because of Two's Complement
.
I tried to convert Hex String into Integer, but I got the error.
Here is the code I have tried.
- code
// Extension functions
val Int.asByteArray get() =
byteArrayOf(
(this shr 24).toByte(),
(this shr 16).toByte(),
(this shr 8).toByte(),
this.toByte())
val Int.asHex get() = this.asByteArray.asHexUpper
// Main Code
fun main()
{
println((-1).asHex)
println("FFFFFFFF".toInt(16))
}
- Result
FFFFFFFF
Exception in thread "main" java.lang.NumberFormatException: For input string: "FFFFFFFF"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
Is this intended? or Is this error?
If this is intended, then what should I do?