当前位置:网站首页>【Day_12 0507】二进制插入
【Day_12 0507】二进制插入
2022-08-01 17:40:00 【安河桥畔】
二进制插入
题目来源
牛客网:二进制插入
题目描述
给定两个32位整数n和m,同时给定i和j,将m的二进制数位插入到n的二进制的第j到第i位,保证n的第j到第i位均为零,且m的二进制位数小于等于i-j+1,其中二进制的位数从0开始由低到高。
示例
输入
1024,19,2,6
输出
1100
思路分析
这道题主要考察位运算,题目说明了n的第 j 到 i 位均为0,所以只要将m的最低位和n的第 j 位对齐,进行按位或即可
以1024和19为例:
代码展示
class BinInsert {
public:
int binInsert(int n, int m, int j, int i) {
m<<=j;
return m|n;
}
};
边栏推荐
猜你喜欢

B011 - 51-based multifunctional fingerprint smart lock

B001 - 基于STM32的智能生态鱼缸

Xingtu has been short of disruptive products?Will this M38T from the Qingdao factory be a breakthrough?
![[供应链·案例篇]石油和天然气行业的数字化转型用例](/img/44/9ef9f86f8afb85f49aac1cce55723d.jpg)
[供应链·案例篇]石油和天然气行业的数字化转型用例

B011 - 基于51的多功能指纹智能锁

Bugku-Misc-贝斯手

Shell nl命令详解(显示行号、读取文件)

生物制药产业发展现状和趋势展望

食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?

How can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.
随机推荐
zabbix部署和简单使用
金仓数据库 MySQL 至 KingbaseES 迁移最佳实践(2. 概述)
XAML WPF项目groupBox控件
C语言理论--笔试面试基础稳固
SQL的ROUND函数用法及其实例
中信证券是国内十大券商吗?怎么开户安全?
Flask框架实战
理财产品的月年化收益率怎么算?
XAML WPF item groupBox control
06 redis cluster structures
数字化采购管理系统开发:精细化采购业务流程管理,赋能企业实现“阳光采购”
块级元素、行内元素、行内块元素
Daily Yuxian Big Defeat
SQL的substring_index()用法——MySQL字符串截取
QT基础功能,信号、槽
【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
关于2022年深圳市福田区支持高端服务业发展项目的申报通知
QT_QThread thread
How can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.
LeaRun.net快速开发动态表单