2

Example:
x = 0xF0AA, now when I do x = x << 8, I will get x == 0xAA00. Right side (8 bits) of new value is filled with zeros. Is there a method int .NET Framework which can fill this bits with that bits from left side (with disapeared part)?
Result should be x == 0xAAF0.

apocalypse
  • 5,764
  • 9
  • 47
  • 95

1 Answers1

2

What you want to do is called a circular shift. It's easy enough to emulate with two shifts and an or.

UInt32 RotateLeft(Uint32 n, int howManyBits) {
    return n << howManyBits | n >> (32 - howManyBits);
}
Hampus Nilsson
  • 6,692
  • 1
  • 25
  • 29