Shift N to the left m-bit int byte_to_left_move (int n, int m) { int i, ret = 1; if (n = = 0 | | n < 0) { return; } if (n = = 1) {for (i = 0; i < m; i++) ret *= n * 2; } if (n > 1) {for (i = 0; i < m; i++) ret *= n; } return ret;} Shift N to the right m-bit int byte_to_right_move (int n, int m) { int i, ret = 1; if (n = = 0 | | n < 0) { return; } if (n = = 1) { ret = 0; } if (n > 1) {for (i = 0; i < m; i++) { n/= 2; } ret = n; } return ret;}Idle bored, I wrote two API interface, test pass, but may not be perfect, but the initial implementation of a number to the left to move the N-bit algorithm, the algorithm is very simple, is the cycle of multiplication and divide, this time understand, in fact, the basis is very important, such as the beginning of the C language, The teacher teaches the multiplicative and cumulative algorithm, although simple, but still very large, these two APIs also have similar, such as left-shifted interface has the nature of the multiplicative on the inside.
Embedded C Development---Use loops to move left to right