当前位置:网站首页>LeetCode做题小结
LeetCode做题小结
2022-08-09 16:59:00 【Mosquito...】
1. 移位运算的运用
1. 将二进制转化为十进制
通过移位得到结果,另外一种方法是采用 2 0 ⋅ x 0 + 2 1 ⋅ x 1 + . . . + 2 n ⋅ x n 2^0\cdot x_0+2^1\cdot x_1+...+2^n\cdot x_n 20⋅x0+21⋅x1+...+2n⋅xn得到,但注意无符号整数类型和有符号整数类型的判断,不考虑的话直接采用第二种方法可能会导致溢出。
// number[i]存储第i位的数值(从地位开始计算,即number[0]的权值为1,number[1]的权值为2,依次类推
for (int i = 0; i < 32; ++i) {
//res += number[i] * pow(2, i); 这样可能会产生上溢出
res = res | (number[i] << i);
}
2. 乘以2除以2的计算
直接用移位运算即可
边栏推荐
猜你喜欢
随机推荐
进行知识管理的好处有哪些?
What platform is EPIC?
动态RDLC报表(一)
The senior told me that the MySQL of the big factory is connected through SSH
Discuz!论坛程序安装+模板配置教程
谭中意:你知道 “开源女王” 是谁吗?
One-key login principle of local number
MASA Stack 第三期社区例会
An in-depth understanding of the implementation principle of Hybrid
What is test development and why is it so popular now?
怎样选择一个好的SaaS知识库工具?
.NET 6 study notes (4) - Solve the Nullable warning in VS2022
About the common Hook encapsulation of DOM (2)
openEuler 熊伟:如何看待开源社区中的 SIG 组织模式?
In-depth understanding of MySQL common data types and data type selection optimization
动态RDLC报表(五)
测试开发是什么,为什么现在这么吃香?
The most complete architect knowledge map in history
dotnet 6 为什么网络请求不跟随系统网络代理变化而动态切换代理
本机号码一键登录原理








