Advertisement
ollikolli

Untitled

Mar 6th, 2024
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.40 KB | None | 0 0
  1.   def leftRotate(w: Long, k: Int): Long =
  2.     val wBinary = (0 to 63).toArray.map(j => (w >> 63 - j) & 1).flatMap(b => "%d".format(b))
  3.     println(new String(wBinary))
  4.     var j = 0
  5.     val rArray = Array.fill(64)('1')
  6.     while j <= 63 do
  7.       rArray((j + k)%64) = wBinary(j)
  8.       j += 1
  9.  
  10.     val rString = new String(rArray)
  11.     println(rString)
  12.     java.lang.Long.parseLong(rString.reverse, 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement