将M插入N的二进制i位到j位之间

来源:互联网 发布:windows10自运行软件 编辑:程序博客网 时间:2024/05/09 04:21
#include <iostream>int main(){    unsigned int N = 1024;    unsigned int M = 21;    unsigned int i = 2, j = 6;    unsigned int temp = ~0;    unsigned int left = temp >> (32 - i);    std::cout << "left: " << left << std::endl;    unsigned int right = temp << (j + 1);    std::cout << "right: " << right << std::endl;    unsigned int res = (N & (left | right)) | (M << i);    std::cout << "result: " << res << std::endl;    return 0;}

原创粉丝点击