brewersfan1976

mirror_bits.rb

Sep 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.21 KB | None | 0 0
  1. def mirrorBits(a)
  2.     string = a.to_s(2)
  3.     x = string.length - 1
  4.     mirror = ""
  5.    
  6.     while (x >= 0)
  7.           mirror = mirror + string[x]
  8.           x = x - 1
  9.     end
  10.    
  11.     return mirror.to_i(2)
  12. end
Advertisement
Add Comment
Please, Sign In to add comment