当前位置:网站首页>整型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
边栏推荐
- Boot 和 Cloud 的版本选型
- Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
- [confluence] JVM memory adjustment
- 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
- Compiler optimization (4): inductive variables
- Some important knowledge of MySQL
- 浏览积分设置的目的
- LeetCode_ 7_ five
- 一锅乱炖,npm、yarn cnpm常用命令合集
- # 欢迎使用Markdown编辑器
猜你喜欢

项目经理『面试八问』,看了等于会了

位运算介绍

openEuler 资源利用率提升之道 01:概论

J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar

CSDN syntax description

Detailed explanation of Flink parallelism and slot

Some important knowledge of MySQL

Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!

微信公众号OAuth2.0授权登录并显示用户信息

vulnhub之tre1
随机推荐
开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
JVM class loading mechanism
831. KMP string
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
A pot of stew, a collection of common commands of NPM and yarn cnpm
LeetCode_7_5
剑指 Offer II 013. 二维子矩阵的和
MIT科技评论文章:围绕Gato等模型的AGI炒作可能使人们忽视真正重要的问题
谷歌seo外链Backlinks研究工具推荐
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
How to buy bank financial products? Do you need a bank card?
Sword finger offer II 013 Sum of two-dimensional submatrix
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
Kubernetes——kubectl命令行工具用法详解
【STL】vector
干货分享|DevExpress v22.1原版帮助文档下载集合
线性基
The project manager's "eight interview questions" is equal to a meeting
Throughput
AD域组策略管理
