当前位置:网站首页>整型int的拼接和拆分
整型int的拼接和拆分
2022-07-07 18:01:00 【junxuezheng】
一、int的拼接和拆分
1.拆分
- int 数据类型占据32位。
- 拆分成高30位和低2位,其实就是把把32位的高30位和低2位的数据取出来。
- 例如int a =14
- a存储的十六进制:0x0000 000E
- a存储的二进制:0000 0000 0000 0000 | 0000 0000 0000 1110
- a拆分后的高30位是:(二进制)0000 0000 0000 0000 | 0000 0000 0000 11,换算成10进制为3
- a拆分后的低2位是:(二进制)10,换算成十进制为2.
2.拼接
拼接和拆分的顺序是反的,
简单说就是把数据a的高30位左移2位(二进制0000 0000 0000 0000 | 0000 0000 0000 11),
然后加上低2位的数据(二进制10)
二、c++ demo
#include <iostream>
using namespace std;
int main()
{
int a = 14;
// 把int a拆分成左30位,右2位
int a_left = (a & 0xfffffffc) >> 2;
int a_right = (a & 0xfffffff3);
// 合并
int a_ori = (a_left << 2) + a_right;
std::cout << "a_left="<<a_left<<endl;
std::cout << "a_left=" << a_right << endl;
std::cout << "a_ori=" << a_ori << endl;
}
输出
a_left=3
a_left=2
a_ori=14
边栏推荐
- R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
- R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
- 力扣 88.合并两个有序数组
- Introduction to bit operation
- ASP. Net kindergarten chain management system source code
- mock.js从对象数组中任选数据返回一个数组
- MSE API学习
- RESTAPI 版本控制策略【eolink 翻译】
- 谷歌seo外链Backlinks研究工具推荐
- Cloud component development and upgrading
猜你喜欢
随机推荐
R language ggplot2 visualization: use the ggdensity function of ggpubr package to visualize the packet density graph, and use stat_ overlay_ normal_ The density function superimposes the positive dist
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
JVM GC垃圾回收简述
力扣 2319. 判断矩阵是否是一个 X 矩阵
毕业季|遗憾而又幸运的毕业季
vulnhub之tre1
关于自身的一些安排
mysql 的一些重要知识
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
The project manager's "eight interview questions" is equal to a meeting
Mysql, sqlserver Oracle database connection mode
831. KMP string
线性基
使用高斯Redis实现二级索引
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
Version selection of boot and cloud
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
pom. XML configuration file label: differences between dependencies and dependencymanagement
Equals method
Boot 和 Cloud 的版本选型