Homepage › Forums › Articles › Programming › C, C++, and C# › C Code Examples: Array Rotations
Tagged: array, c-language, c-sharp, code, cplusplus, example, objective-c, programming, sample
This topic was published by DevynCJohnson and viewed 1707 times since "". The last page revision was "".
Viewing 1 post (of 1 total)
- AuthorPosts
Rotate an Array of Bytes to the Left
void array_rotl(uint8_t *array, const size_t len, const uint32_t num_shifts) { // Rotate an array to the left in-place if ((len > 0x02) && (num_shifts != 0x00)) { register uint32_t i, j; register uint8_t first; for (i = num_shifts; i != 0x00; --i) { first = array[0x00]; for (j = 0x00; j < (uint32_t)(len - 0x01); ++j) array[j] = array[j + 0x01]; array[j] = first; } } }
Rotate an Array of Bytes to the Right
void array_rotr(uint8_t *array, const size_t len, const uint32_t num_shifts) { // Rotate an array to the right in-place if ((len > 0x02) && (num_shifts != 0x00)) { register uint32_t i, j; register uint8_t last; for (i = num_shifts; i != 0x00; --i) { last = array[len - 0x01]; for (j = (uint32_t)len; --j;) array[j] = array[j - 0x01]; array[0x00] = last; } } }
Rotate Char Array of Bytes to the Left
void chararray_rotl(char *array, const size_t len, const uint32_t num_shifts) { // Rotate a char array to the left in-place if ((len > 0x02) && (num_shifts != 0x00)) { register uint32_t i, j; register char first; for (i = num_shifts; i != 0x00; --i) { first = array[0x00]; for (j = 0x00; j < (uint32_t)(len - 0x01); ++j) array[j] = array[j + 0x01]; array[j] = first; } } }
Rotate Char Array of Bytes to the Right
void chararray_rotr(char *array, const size_t len, const uint32_t num_shifts) { // Rotate a char array to the right in-place if ((len > 0x02) && (num_shifts != 0x00)) { register uint32_t i, j; register char last; for (i = num_shifts; i != 0x00; --i) { last = array[len - 0x01]; for (j = (uint32_t)len; --j;) array[j] = array[j - 0x01]; array[0x00] = last; } } }
Further Reading
- Programming and Development - https://dcjtech.info/topic/programming-and-development/
- C Programming Article Forum - https://dcjtech.info/forum/articles/programming/c-c-and-c/
- AuthorPosts
Viewing 1 post (of 1 total)