当前位置:网站首页>整型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
边栏推荐
猜你喜欢
Make this crmeb single merchant wechat mall system popular, so easy to use!

Some important knowledge of MySQL

vulnhub之Funfox2

PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!

干货分享|DevExpress v22.1原版帮助文档下载集合

vulnhub之tre1

【STL】vector

数据孤岛是企业数字化转型遇到的第一道险关

Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse

Nunjuks template engine
随机推荐
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
equals 方法
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
SQL common optimization
小试牛刀之NunJucks模板引擎
Ways to improve the utilization of openeuler resources 01: Introduction
[confluence] JVM memory adjustment
【STL】vector
位运算介绍
力扣 1037.有效的回旋镖
Semantic slam source code analysis
Tp6 realize Commission ranking
vulnhub之school 1
使用高斯Redis实现二级索引
tp6 实现佣金排行榜
实训九 网络服务的基本配置
CSDN syntax description
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
Compiler optimization (4): inductive variables
MIT科技评论文章:围绕Gato等模型的AGI炒作可能使人们忽视真正重要的问题
