Is there a Rotate Bits Right in Ruby ?
Or how can I do that please.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Some facts:
<<and>>to shift, but no built-in rotate operator. You have to fake it.Fixnumclass automatically promotes toBignumwhen the value exceeds the machine word size. This includes numbers that would fit in an unsigned word but not a signed word — for example,0xffffffffis a positiveBignum, not a negativeFixnum.So if you want a rotate operation, you a) have to write it using the shift operators, b) either hardcode 32 or 64 bits or ask
Fixnumfor the word size, and c) accept that the result might end up being aBignum.That being said, this might work: