On Aug 13, 3:00 am, Simon King <simon.k...@uni-jena.de> wrote: > Hi Santanu, hi Benjamin, > > On 13 Aug., 06:23, Benjamin Jones <benjaminfjo...@gmail.com> wrote: > > > On Aug 12, 9:38 pm, Santanu Sarkar <sarkar.santanu....@gmail.com> > > See section 5.4.1 of: > > >http://docs.python.org/library/stdtypes.html > > I doubt that that is answering the question: "I have 64 bit integer > N. I want to rotate bits of N cyclically 5 bits right and 5 bits left > to generate two integers N1, N2."
You're right, I didn't mean to leave a complete answer to the question, just the hint about shifting that I had time to post. > > sage: def rotate(I,n): > ....: right_end = I%(2^n) > ....: left_end_shifted = I>>n > ....: return left_end_shifted+(right_end<<(I.nbits()-n)) > ....: > sage: I = ZZ(randint(100,500)) > sage: I.binary() > '11101100' > sage: rotate(I,3).binary() > '10011101' > > Or do you mean that you consider ALL 64 bits of your integer, even > leading zeroes? Then I guess you have to replace "I.nbits()-n" by "64- > n". That was cyclic rotation n bits to the right side, I hope you are > able to modify the example for cyclic rotation to the left side. > > Cheers, > Simon This is exactly what I had in mind. Good example.. I didn't realize that Sage integers had a binary() method. -- BFJ -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org