首页 > 其他 > 详细

5.1---二进制数插入(CC150)

时间:2015-12-24 13:15:21      阅读:244      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public static int binInsert(int n, int m, int i, int j) {
        // write code here
//        return n | (m << i);
        int allOnes = ~0;
        int left = allOnes << (j + 1);
        int right = (1 << i) - 1;
        
        int mask = left | right;
        int n_cleared = mask & n;
        int m_shifted = m << i;
       return n_cleared | m_shifted;
    }
    public static void main(String[] args){
        System.out.println(binInsert(4,1,1,1));
    }
}

 

5.1---二进制数插入(CC150)

原文:http://www.cnblogs.com/yueyebigdata/p/5072683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!