: : : : Write a program to rotate an integer,m in the right hand direction ,by a specified no of bits,n. those who give the code pls explain as well.Thanks
: : : Here's the program:
: : : ror ax, 1
: : : I think it's about 2 bytes or so.
: : :
: : That's asm. Using C++, you will need a couple of hundred lines of code.
:
: - Here are my 100 lines. If you need left rotation, too, think of using an extra bool in the call or negative numbers for by. Sorry no indentation possible. FDrache.
:
: int RotateRight(int Number, short by)
: {
: int i;
: bool on;
:
: by = By % 32; // for safety
:
: for (i = 1; i <= by; i++)
: {
: // The LSB goes lost by shifting right
: on = (Number & 1) > 0; // Save LSB
: Number = Number >> 1;
: if (on)
: Number |= 0x80000000; // Highest Bit of 32
: } // for i
:
: return Number;
: }
:
Come on! We were making fun of the initial poster. Didn't you get that?
You are probably the first person here that did someone else's homework.
Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl