Bitwise AND of Numbers Range

位操作

public class Solution {

    public int rangeBitwiseAnd(int m, int n) {

        // ref http://www.cnblogs.com/grandyang/p/4431646.html

        // 位操作运算 http://blog.csdn.net/morewindows/article/details/7354571

        int i  =0;

        while(m!=n){

            m >>=1;

            n >>=1;

            i++;

        }

        return (m<<=i);

    }

}

 

你可能感兴趣的:(number)