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