Kotlin Program to Convert Byte Array to Hexadecimal

Kotlin Program to Convert Byte Array to Hexadecimal. To convert byte array to a hex value, we loop through each byte in the array and use String ‘s format().

Kotlin Program to Convert Byte Array to Hexadecimal

Source Code

fun main(args: Array<String>) {

    val bytes = byteArrayOf(12, 2, 15, 11)

    for (b in bytes) {
        val st = String.format("%02X", b)
        print(st)
    }

}

Output