Advertisement
Guest User

Binary to Text (ASCII) Conversion

a guest
Apr 6th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1. object Kata {
  2.     def binaryToString(input: String): String = {
  3.     @scala.annotation.tailrec
  4.     def toNumber(st: String, two: Int = 128, number: Int = 0): Int =
  5.       if (st.isEmpty) number
  6.       else toNumber(st.tail, two / 2, st.head.asDigit * two + number)
  7.  
  8.     input.grouped(8).map[Char](s => toNumber(s).toChar).mkString
  9.   }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement