Kotlin Program to Convert ASCII Code to Character

In this post, we will learn about how to convert ASCII Code to Character in Kotlin programming language.

Kotlin Program to Convert ASCII Code to Character

We use toChar() function to convert any value to character. So, we will use this function in our example.

Sourcecode –

package tutorial

fun main() {

    val asciiValue = 97

    // Get ASCII value of exampleChar
    val charValue = asciiValue.toChar()

    println("Character value of $asciiValue is $charValue")
}

When you run the program, output will be

Character value of 97 is a
Explanation:

In this example, we have taken 97 as ASCII value. We stored this value in variable asciiValue

Then, We get it’s character value using toChar() method and stored it in another variable charValue.

Finally, we print result using println() function.

Leave a Reply