O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Overflow Checking

So far, we’ve omitted an all-important detail from this discussion: overflow checking. Due to the limited precision offered by the built-in types—ignoring the new .NET 4.0 BigInteger type—there will be places where things go wrong. For example, take the biggest 32-bit integer value and add 1 to it. What’s the result going to look like? To see what’s going on, let’s take a look at the bit representation for int.MaxValue. To do this, Visual Studio can help again, as illustrated in Figure 5.10.

Image

FIGURE 5.10 Hexadecimal display for variables.

The result will be 0x7fffffff, from which we can easily get to bit representation. Notice ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required