Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to convert Int to Hex String in Kotlin?
Kotlin is statistically typed language and it is built on JVM. Kotlin is cent percent comparable with Java. Hence, some of the Java functions can be used in Kotlin as well.
In this article, we will take an example to demonstrate how we can use a Java class function convert an Int in Kotlin to its correponding Hex String.
Example – Converting Int to Hex String in Kotlin
In this example, we will use the Java class function toHexString().
import java.lang.*
fun main(args: Array<String>) {
val hexString = java.lang.Integer.toHexString(-66)
println("Hex String for negative Number: " +hexString)
val positiveNumber = java.lang.Integer.toHexString(166)
println("Hex String for positive Number: " +positiveNumber)
}
Output
On execution, it will produce the following output −
Hex String for negative Number: ffffffbe Hex String for positive Number: a6
Advertisements
