<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda" -->

---
title: On finding the average of two unsigned integers without...
description: The average of two unsigned integers, rounding toward zero, sounds easy. But it gives the wrong answer in the face of integer overflow. For example, if...
canonical: https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: On finding the average of two unsigned integers without overflow | daily.dev
og:description: The average of two unsigned integers, rounding toward zero, sounds easy. But it gives the wrong answer in the face of integer overflow. For example, if...
og:url: https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda
og:image: https://api.daily.dev/og/posts/h5An_8YdA.png
og:image:alt: On finding the average of two unsigned integers without overflow
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# On finding the average of two unsigned integers without overflow

**[DevBlogs](https://daily.dev/sources/devblogs)** · 10 min read · 0 upvotes · 0 comments

## Summary

The average of two unsigned integers, rounding toward zero, sounds easy. But it gives the wrong answer in the face of integer overflow. For example, if unsigned integers are 32 bits wide, then it says that average(0x80000000U, 0x8000000U) is zero.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223>

---

[View this post on daily.dev](https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"On finding the average of two unsigned integers without overflow","url":"https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda"},"datePublished":"2022-02-07T15:36:46.250Z","dateModified":"2022-02-07T15:36:46.256Z","description":"The average of two unsigned integers, rounding toward zero, sounds easy. But it gives the wrong answer in the face of integer overflow. For example, if...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/08147523a7da9288cfd6c7d104e7ca59","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/08147523a7da9288cfd6c7d104e7ca59","isAccessibleForFree":true,"articleSection":"DevBlogs","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DevBlogs","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/8f68b453325f482ebeb73fb780092713","url":"https://daily.dev/sources/devblogs"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/on-finding-the-average-of-two-unsigned-integers-without-overflow-h5an-8yda","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DevBlogs","item":"https://daily.dev/sources/devblogs"},{"@type":"ListItem","position":3,"name":"On finding the average of two unsigned integers without overflow"}]}
```

