Is there a way to initialize FourCharCode with Kot...
# kotlin-native
m
Is there a way to initialize FourCharCode with Kotlin Native I have some C code and I want to rewrite
#define test 'test'
That's how you can get the code of a C FourCharCode in Koltin
Copy code
val charList = listOf('t', 'e', 's', 't')
    
val code = (charList[0].toInt() shl 24) or
           (charList[1].toInt() shl 16) or
           (charList[2].toInt() shl 8) or
           charList[3].toInt()
m
Copy code
fun String.asFourCharCode(): UInt {
    require(length == 4) { "Code length must be 4 characters" }

    var hash: UInt = 0u

    for (char in this) {
        hash = (hash shl 8) or char.code.toUInt()
    }

    return hash
}
thank you color 1