wes d2a2ba9e15 first commit 4 years ago
..
README.md d2a2ba9e15 first commit 4 years ago
code.cpp d2a2ba9e15 first commit 4 years ago
unitTest.cpp d2a2ba9e15 first commit 4 years ago

README.md

Bit Rotation

by Matt tags: bit_operations, strings

Summary

C++ offers some bit operations but not bit rotation. To complete that, create a function that takes three parameters: n: Integer, which in binary representaion should be rotated. m: Number of rotation steps that should be performed. d: Boolean value; true = rotation right, false = rotation left. Your function should return an integer as a result of its rota

Instructions

C++ offers some bit operations but not bit rotation. To complete that, create a function that takes three parameters:

  1. n: Integer, which in binary representaion should be rotated.
  2. m: Number of rotation steps that should be performed.
  3. d: Boolean value; true = rotation right, false = rotation left.

Your function should return an integer as a result of its rotated binary representation.

Examples

bitRotate(8, 1, true) ➞ 4
// 8 in bin: 1000, rotated 1 step to the right: 0100, in dec: 4

bitRotate(16, 1, false) ➞ 1
// 16 in bin: 10000, rotated 1 step to the left: 00001, in dec: 1

bitRotate(17, 2, false) ➞ 6
// 17 in bin: 10001, rotated 2 steps to the left: 00110, in dec: 6

Notes

For parameters use unsigned integers only.