当前位置:网站首页>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)
边栏推荐
- Install pytoch geometric
- (4) Canal multi instance use
- Canoe panel learning video
- MySQL information_ Schema database
- js获取对象中嵌套的属性值
- Thinkphp6.0 middleware with limited access frequency think throttle
- Descriptive analysis of data distribution characteristics (data exploration)
- Detectron: train your own data set -- convert your own data format to coco format
- 如何展开Collapse 的所有折叠面板
- 4G wireless all network solar hydrological equipment power monitoring system bms110
猜你喜欢
![[microservice] Nacos cluster building and loading file configuration](/img/50/7af220c57a06eb186729c9882d9dab.png)
[microservice] Nacos cluster building and loading file configuration

Leetcode question brushing record | 206_ Reverse linked list

19. Framebuffer application programming

Impact relay jc-7/11/dc110v

Configure cross compilation tool chain and environment variables

js arguments参数使用和详解

1480. Dynamic sum of one-dimensional array

QT get random color value and set label background color code

QT 获取随机颜色值设置label背景色 代码

Penetration tool - sqlmap
随机推荐
left_and_right_net正常版本
剑指 Offer II 038. 每日温度
Kubernets first meeting
fastjson
tutle时钟改进版
transformer坑了多少算力
Google Chrome browser will support the function of selecting text translation
Excel comparator
JS扁平化数形结构的数组
Understanding of cross domain and how to solve cross domain problems
Win10 clear quick access - leave no trace
left_ and_ right_ Net normal version
Functions in C language (detailed explanation)
Notes and notes
Lightroom import picture gray / Black rectangular multi display
Nexus 6p从8.0降级6.0+root
input显示当前选择的图片
C语言中的函数(详解)
FRP intranet penetration, reverse proxy
How to get the parent node of all nodes in El tree