0

Value: 1,921,222, is too large to be stored as a short, so numeric overflow occurs and it becomes 20,678.

Can anyone demonstrate the process of 1,921,222 becoming 20,678 ? how to “wraps around” to the next lowest value and counts up from there to get 20,678 Thank you in advance

1 Answers1

0

In language C, the "short" type has 2 bytes. Every integer value is treated by the compiler as a 32-bit or 4-byte "int" type (this can vary depending on the compiler).

 short s = 1921222;

In this sentence you are losing 2 bytes of data:

                Information that remains in the variable (2 bytes)
                      ^         ^
 00000000 00011101 01010000 11000110   ->  total data (4 bytes, 32 bits)
    v        v
 Information discarded when you put this value in a short type.

In other words, you "crop" the data, leaving only the part that fits the specified type.

01010000 11000110

"01010000 11000110" is 20678.

This site can help you to understand better how this process works: https://hexed.it/