面试金典--5.1

题目描述:给定N,M两个32位整数,以及i、j,将i、j之间的位置为数M对应的二进制位

 1 #include <iostream>
 2 #include <string>
 3 #include <fstream>
 4 #include <map>
 5 #include <algorithm>
 6 #include <vector>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <stack>
10 
11 using namespace std;
12 
13 int main()
14 {
15     int N,M;
16     cin>>N>>M;
17     int i,j;
18     cin>>i>>j;
19     bitset<32> b1(N);
20     M = M<<i;
21     bitset<32> b2(M);
22     int k = i;
23     while(k <= j)
24     {
25         b1.reset(k);
26         ++k;
27     }
28     N = (int)b1.to_ulong();
29     N = N|M;
30     cout<<N<<endl;
31     return 0;
32 }

 

转载于:https://www.cnblogs.com/cane/p/3789415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值