0

I need to do a 3 bit left end around rotation in C++.

So far I have:

A[i] = (A[i] << 3)|(A[i] >> 5);

A is an unsigned char array.

Is this correct? If not how can I fix it? Also what is the best way to test and see if this is correct?

Thanks

user2177896
  • 103
  • 1
  • 2
  • 7

1 Answers1

1

Looks fine to me.

If you really want to test it, work out a bunch of inputs and outputs by hand and check your program produces them.

Or devise another method that you're absolutely sure will produce results (eg convert unsigned char to binary string, rotate the string, convert back to unsigned char) and compare the two against all 256 possible inputs.

paddy
  • 52,396
  • 6
  • 51
  • 93