1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package cn.gygxzc.envir.utils
- import java.util.*
- object Byte2Hex {
-
- fun byte2Hex(b: Byte): String {
- var hex = Integer.toHexString(b.toInt())
- if (hex.length > 2) {
- hex = hex.substring(hex.length - 2)
- }
- while (hex.length < 2) {
- hex = "0$hex"
- }
- return hex
- }
-
- fun byte2Hex(bytes: ByteArray): String {
- val formatter = Formatter()
- for (b in bytes) {
- formatter.format("%02x", b)
- }
- val hash = formatter.toString()
- formatter.close()
- return hash
- }
- }
|