Skip to content

Commit

Permalink
feat(Experience): add data type helper methods
Browse files Browse the repository at this point in the history
add data type helper methods:
- ByteArray to HexString (String)
- String to Binary (ByteArray)
  • Loading branch information
hamada147 committed Sep 12, 2022
1 parent 2663a1b commit c52cd79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.iohk.prism.hashing.internal

fun ByteArray.toHexString(): String {
return joinToString("") { (0xFF and it.toInt()).toString(16).padStart(2, '0') }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.iohk.prism.hashing.internal

fun String.toBinary(): ByteArray {
val blen = this.length / 2
val buf = ByteArray(blen)
for (i in 0 until blen) {
val bs = this.substring(i * 2, i * 2 + 2)
buf[i] = bs.toInt(16).toByte()
}
return buf
}

0 comments on commit c52cd79

Please sign in to comment.