wes d2a2ba9e15 first commit | 4 anos atrás | |
---|---|---|
.. | ||
README.md | 4 anos atrás | |
code.cpp | 4 anos atrás | |
unitTest.cpp | 4 anos atrás |
by Matt tags: bit_operations, strings
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
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 rotated binary representation.
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
For parameters use unsigned integers only.