当前位置:网站首页>Average two numbers
Average two numbers
2022-07-04 06:02:00 【AppNinja】
// average.cpp : Defines the entry point for the console application .
//
#include "stdafx.h"
// There is Bug edition : Integer overflow
unsigned average1(unsigned a, unsigned b)
{
return (a + b) / 2;
}
// The following is the correct version :
unsigned average2(unsigned low, unsigned high)
{
return low + (high - low) / 2;
}
unsigned average3(unsigned a, unsigned b)
{
return (a / 2) + (b / 2) + (a & b & 1);
}
unsigned average4(unsigned a, unsigned b)
{
return (a & b) + (a ^ b) / 2;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10;
int b = 7;
unsigned int result = average4(0x80000000U, 0x80000000U);
printf("%d", result);
return 0;
}
On finding the average of two unsigned integers without overflow - The Old New Thing (microsoft.com)
边栏推荐
- left_and_right_net正常版本
- 724. Find the central subscript of the array
- Learning multi-level structural information for small organ segmentation
- Gridview出现滚动条,组件冲突,如何解决
- Excel 比较日器
- Steady! Huawei micro certification Huawei cloud computing service practice is stable!
- QT qtablewidget table column top requirements ideas and codes
- BUU-Crypto-[GXYCTF2019]CheckIn
- JS扁平化数形结构的数组
- 安装 Pytorch geometric
猜你喜欢

Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)

APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?
![[excel] PivotChart](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[excel] PivotChart

体验碎周报第 102 期(2022.7.4)
![[Excel] 数据透视图](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[Excel] 数据透视图

How to solve the component conflicts caused by scrollbars in GridView

JS execution mechanism

BUU-Pwn-test_ your_ nc

Online shrimp music will be closed in January next year. Netizens call No

gslb(global server load balance)技术的一点理解
随机推荐
Invalid revision: 3.18.1-g262b901-dirty
BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
【微服务】Nacos集群搭建以及加载文件配置
win10清除快速访问-不留下痕迹
How to get the parent node of all nodes in El tree
对List进行排序工具类,可以对字符串排序
接地继电器DD-1/60
(4) Canal multi instance use
1480. Dynamic sum of one-dimensional array
安装 Pytorch geometric
The difference between PX EM rem
注释与注解
BUU-Real-[PHP]XXE
Penetration tool - sqlmap
JSON Web Token----JWT和傳統session登錄認證對比
Tutle clock improved version
Input displays the currently selected picture
AWT常用组件、FileDialog文件选择框
Descriptive analysis of data distribution characteristics (data exploration)
体验碎周报第 102 期(2022.7.4)