当前位置:网站首页>Application of bit operation in C language
Application of bit operation in C language
2022-06-12 13:24:00 【shlyyy】
C Application of language bit operation
One 、 Find the absolute value
The absolute value of an integer
int AbsInt(int n)
{
int i = n >> 31; // if n >= 0, i = 0; else i = 0xffffffff = -1
n = n ^ i; // if i = 0, n = n; else i = 0xffffffff, n = ~n
return n - i; // if i = 0, n - i = n; else i = -1, n - i = n + 1
}
The absolute value of floating point numbers
float AbsFloat(float flt)
{
*(size_t*)&flt = (*(size_t*)&flt & 0x7fffffff);
return flt;
}
double AbsDouble(double dbl)
{
*((size_t*)&dbl + 1) = (*((size_t*)&dbl + 1) & 0x7fffffff);
return dbl;
}
边栏推荐
- Symbolic constant, const qualifier
- The goods are full. You must take this knowledge
- 安装MySQL时出错,照着下面这个链接,做到cmd就不行了
- Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
- 成功定级腾讯T3-2,万字解析
- 2061: [example 1.2] trapezoidal area
- import torch_geometric 第一个图网络例子
- Informatics Olympiad all in one 1000: introductory test questions
- 2063: [example 1.4] cattle eat grass
- 深度学习的多个 loss 是如何平衡的?
猜你喜欢
Further understanding of the network
LeetCode滑动窗口刷题总结
嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法
Eight misunderstandings are broken one by one (2): poor performance? Fewer applications? You worry a lot about the cloud!
Summary of question brushing in leetcode sliding window
Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
成功跳槽阿里,进阶学习
Experience and learning path of introductory deep learning and machine learning
The goods are full. You must take this knowledge
嵌入式系统硬件构成-嵌入式系统硬件体系结构
随机推荐
Script引入CDN链接提示net::ERR_FILE_NOT_FOUND问题
Automatic Generation of Visual-Textual Presentation Layout
Pytoch official fast r-cnn source code analysis (I) -- feature extraction
import torch_ Geometric first graph network example
Dameng database DM8 Windows environment installation
[you code, I fix] whitesource was officially renamed mend
深度学习的多个 loss 是如何平衡的?
[embedded] serial communication and its case
嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法
Unittest framework
Successful job hopping Ali, advanced learning
嵌入式系统硬件构成-基于ARM的嵌入式开发板介绍
JVM 运行时参数
5V升压到12.6V的锂电池充电IC芯片方案FS4062B
创新实训(十)高级界面美化
The problem of Joseph in Informatics
关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?
Build an embedded system software development environment - build a cross compilation environment
Overview of embedded system 2- composition and application of embedded system
import torch_geometric 加载一些常见数据集