Alle boeken

Professioneel

Apps Over Coach Inloggen Begin met lezen

Computer Science · Begrippenlijst

Wat is Integer overflow?

Definition 2.2 University Computer Science — Year 1 · Hoofdstuk 2 — C: Types, Operators and Control Flow

An integer overflow happens when the exact result of an operation on integers lies outside the range of its type. For unsigned types C defines the result: it is the exact result modulo 2N2^N, so unsigned arithmetic never overflows in the language’s sense, it wraps. For signed types the behaviour is undefined (Section 2.5).

The 256 bit patterns of an 8-bit integer on a circle, adding 1 turning clockwise. Each pattern has an unsigned reading (outside) and a two’s complement reading (inside). Unsigned arithmetic wraps between 255 and 0; signed arithmetic has its seam between 127 and -128, and crossing it is undefined behaviour in C.
The 256 bit patterns of an 8-bit integer on a circle, adding 1 turning clockwise. Each pattern has an unsigned reading (outside) and a two’s complement reading (inside). Unsigned arithmetic wraps between 255 and 0; signed arithmetic has its seam between 127 and −128-128, and crossing it is undefined behaviour in C.
Lees in het hoofdstuk →