FreewareFire
Active member
- Joined
- May 23, 2003
- Messages
- 28
Hi together!
Ive searched for a class which rotates a value bitwise! By using only the << or >> Operator, the value will lost bits, because they filled with 0 ! Did someone know how i rotate a value without losing the bits? The value is 32 bits, unsigned!
This is an example for C++, but i cant get it work right for C#...
unsigned char ror(unsigned char val)
{
int highbit;
if(val & 0x80) // 0x80 is the high bit only
highbit = 1;
else
highbit = 0;
// Left shift (bottom bit becomes 0):
val >>= 1;
// Rotate the high bit onto the bottom:
val |= highbit;
return val;
}
Thank you!
Ive searched for a class which rotates a value bitwise! By using only the << or >> Operator, the value will lost bits, because they filled with 0 ! Did someone know how i rotate a value without losing the bits? The value is 32 bits, unsigned!
This is an example for C++, but i cant get it work right for C#...
unsigned char ror(unsigned char val)
{
int highbit;
if(val & 0x80) // 0x80 is the high bit only
highbit = 1;
else
highbit = 0;
// Left shift (bottom bit becomes 0):
val >>= 1;
// Rotate the high bit onto the bottom:
val |= highbit;
return val;
}
Thank you!