_rotl

G

Guest

Does anyone know how to use the _rotl function or if there an equivalent in C#

Tanks for your hel
 
J

Jon Skeet [C# MVP]

Gilles said:
Does anyone know how to use the _rotl function or if there
an equivalent in C# ?

Anything wrong with using the left shift operator?

int x = y << z;
 
G

Guest

The shift operation replaces the shifted bits by 0
What I would like is that the shifted bit goes to the right of the byte

Any idea

Thank

Gilles
 
J

Josip Medved

The shift operation replaces the shifted bits by 0.
What I would like is that the shifted bit goes to the right of the byte.

(x << z) | (x >> (32 -z))
 
J

Jon Skeet [C# MVP]

Gilles said:
The shift operation replaces the shifted bits by 0.
What I would like is that the shifted bit goes to the right of the byte.

Any idea ?

Ah, I see. Sorry! Well, you could do:

public static uint RotateLeft (uint original, int bits)
{
return (original << bits) | (original >> (32-bits));
}

Does that help?
 
J

Josip Medved

public static uint RotateLeft (uint original, int bits)
{
return (original << bits) | (original >> (32-bits));
}


nice one... only I was 28 seconds faster... :))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top