1 /* 2 * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.serialization 6 7 object HexConverter { 8 private const val hexCode = "0123456789ABCDEF" 9 printHexBinarynull10 fun printHexBinary(data: ByteArray, lowerCase: Boolean = false): String { 11 val r = StringBuilder(data.size * 2) 12 for (b in data) { 13 r.append(hexCode[b.toInt() shr 4 and 0xF]) 14 r.append(hexCode[b.toInt() and 0xF]) 15 } 16 return if (lowerCase) r.toString().lowercase() else r.toString() 17 } 18 } 19