From: Lloyd Linklater Date: 2008-01-23T03:20:14+09:00 Subject: Re: Circular shift Zangief Ief wrote: > I would like to write a simple implementation of *circular shift* > (http://en.wikipedia.org/wiki/Circular_shift). Thank you all for any > ideas :) Well, I am not sure just what you are looking for but here is at least something until one of the sharpies replies: reverse_this_number = 1234 puts reverse_this_number.to_s(2) # before top_bit_set = ((2**(reverse_this_number.size * 8)) & reverse_this_number) != 0 reverse_this_number *= 2 if top_bit_set then reverse_this_number += 1 # set the low order bit end puts reverse_this_number.to_s(2) # after output: 10011010010 100110100100 Note: the output will be missing the leading zero, but it shifts it correctly. This is how it would be internally: 010011010010 100110100100 -- Posted via http://www.ruby-forum.com/.