# Rotate an integer

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

Regs
progeni..

• Use the function 'rotate'. If you don't have it, you'll have to write it or search Google. It is too complex to explain...
bilderbikkel

• : 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
:
:
:
:
: Regs
: progeni..
:
Here's the program:
ror ax, 1
I think it's about 2 bytes or so.
• : : 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
: :
: :
: :
: :
: : Regs
: : progeni..
: :
: 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. Go to your teacher and tell him that this assignment is way too complex for a beginner. Please let us know his reaction...

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl

• : : : 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;
}

• : : : : 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

• [code]
#define ROTATE_INTEGER_R(n) n=(((n) << 31) | ((n) >> 1))

int RotateIntValue (int n, int bits)
{
for (int i=0; i < bits; i++)
{
ROTATE_INTEGER_R (n);
}
}

int a = 74843359;

RotateIntValue (a, 7);
[/code]
• : [code]
: #define ROTATE_INTEGER_R(n) n=(((n) << 31) | ((n) >> 1))
: [/code]

Never saw it before.

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl

• : : : 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
: : :
: : :
: : :
: : :
: : : Regs
: : : progeni..
: : :
: : 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. Go to your teacher and tell him that this assignment is way too complex for a beginner. Please let us know his reaction...
:
:
: Greets,
: Eric Goldstein
: http://www.gvh-maatwerk.nl
:

He didn't even say wich language to use...

Since someone already have done the work, I can do it too...
Here's three lines of code that will do it:
[code]
int i = 0;
int j = 0;
asm{
ror [i], [j]
}
[/code]