当前位置:网站首页>整型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
边栏推荐
- Compiler optimization (4): inductive variables
- R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
- ASP.NET学习& asp‘s one word
- Cuda版本不一致,编译apex报错
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
- 注解。。。
- 力扣 1961. 检查字符串是否为数组前缀
- tp6 实现佣金排行榜
- Welcome to the markdown editor
- R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
猜你喜欢

编译器优化那些事儿(4):归纳变量

mock. JS returns an array from the optional data in the object array

开源OA开发平台:合同管理使用手册

多个线程之间如何协同

谷歌seo外链Backlinks研究工具推荐

Welcome to the markdown editor

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

Interpretation of transpose convolution theory (input-output size analysis)

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

Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
随机推荐
# 欢迎使用Markdown编辑器
MIT科技评论文章:围绕Gato等模型的AGI炒作可能使人们忽视真正重要的问题
Detailed explanation of Flink parallelism and slot
CSDN syntax description
Interpretation of transpose convolution theory (input-output size analysis)
第二十章 使用工作队列管理器(三)
力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
Ways to improve the utilization of openeuler resources 01: Introduction
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
ASP.NET幼儿园连锁管理系统源码
R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
【剑指offer】剑指 Offer II 012. 左右两边子数组的和相等
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!!!
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
8 CAS
浏览积分设置的目的
[confluence] JVM memory adjustment
How to cooperate among multiple threads
PMP practice once a day | don't get lost in the exam -7.7
A pot of stew, a collection of common commands of NPM and yarn cnpm
