当前位置:网站首页>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)
边栏推荐
- 实用的小工具指令
- Experience weekly report no. 102 (July 4, 2022)
- Online shrimp music will be closed in January next year. Netizens call No
- Halcon图片标定,使得后续图片处理过后变成与模板图片一样
- How to clone objects
- 70000 words of detailed explanation of the whole process of pad openvino [CPU] - from environment configuration to model deployment
- Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
- Design and implementation of tcp/ip series overview
- buuctf-pwn write-ups (8)
- 如何实现视频平台会员多账号登录
猜你喜欢

C语言中的函数(详解)

Component、Container容器常用API详解:Frame、Panel、ScrollPane
![[Excel] 数据透视图](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[Excel] 数据透视图

Notes and notes

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

接地继电器DD-1/60

测试岗的中年危机该如何选择?是坚守还是另寻出路?且看下文

Weekly summary (*63): about positive energy
![[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx](/img/a9/72791cbcc6c9da45e89450ab2820c1.jpg)
[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx

JSON web token -- comparison between JWT and traditional session login authentication
随机推荐
Learning multi-level structural information for small organ segmentation
High performance parallel programming and optimization | lesson 02 homework at home
AWT common components, FileDialog file selection box
Install pytoch geometric
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
Penetration tool - sqlmap
C language exercises (recursion)
transformer坑了多少算力
如何实现视频平台会员多账号登录
FRP intranet penetration, reverse proxy
C语言中的函数(详解)
BUU-Reverse-easyre
Upper computer software development - log information is stored in the database based on log4net
QT get random color value and set label background color code
冲击继电器JC-7/11/DC110V
JSON Web Token----JWT和传统session登录认证对比
Impact relay jc-7/11/dc110v
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
Kubernets first meeting
One click filtering to select Baidu online disk files