标签:
class Solution { public: /** *@param n, m: Two integer *@param i, j: Two bit positions *return: An integer */ int updateBits(int n, int m, int i, int j) { if (i == 0 && j == 31) return m; int cnt = j - i + 1; int mask = (1 << cnt) - 1; int nn = (n >> i) & mask; n ^= (nn << i); // clear n |= (m << i); // set return n; } };
标签:
原文地址:http://www.cnblogs.com/tonix/p/4819040.html