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);
    }
}

 

posted @ 2015-05-21 06:05  世界到处都是小星星  阅读(89)  评论(0编辑  收藏  举报