Oerflow Error B.A
Oerflow Error B.A
Overflow occurs when the result of a calculation requires more bits - place values - than are in the available
range. Sometimes, when adding two binary numbers we can end up with an extra digit that doesn’t fit. This is
called an overflow error.
A CPU with a capacity of 8 bits has a capacity of up to 11111111 in binary. If one more bit was added there
would be an overflow error.
Overflow errors happen when the largest number that a register can hold is exceeded. The number of bits that it
can handle is called the word size. Most CPUs use a much bigger word size than 8 bits. Many PCs have a 64-bit
CPU.
The effects of an overflow error can vary. It might make the program crash or it might just ignore the extra
digit on the left and produce an unexpected result.
For example, when using eight bits, the largest number that can be recorded is 11111111 (decimal 255). When
adding together two eight-bit numbers, a situation may occur when the result requires more than eight bits to
hold it. For example, adding the binary numbers 11111110 (decimal 254) and 00000010 (decimal 2) would
give:
The result is actually 100000000 (decimal 256), which requires nine bits. However, as only eight bits are
available to hold the number, the result would be 00000000 (decimal 0). The total is a number bigger than 8
digits, and when this happens the CPU drops the overflow digit because the computer cannot store it
anywhere, and the computer thinks 254 + 2 = 0. As you can see, overflow can have serious consequences for
the validity of calculations.
LOGICAL BINARY SHIFT
TWO’S COMPLEMENT
Example:
To get 2’s complement of a binary number, simply invert the given number and add 1 to the least significant
bit (LSB) of given result.
Here is a quick summary of how to find the 2's complement representation of any decimal number x.
EXAMPLE
This is positive, so all that is needed is to convert to binary and pad to eight bits.
4710 = 1011112
EXAMPLE
1. Interpret 001011112 as a two's complement binary number, and give its decimal equivalent.
To calculate the binary value of a negative decimal number simply start at -128 and work your way back to
the correct answer. In this example the value of -110 is represented as:
Example:
1. Convert the magnitude, 72 to binary. The easiest way is to convert it to hex first. 72÷16 = 4
remainder 8, so 7210 = 4816 = 10010002.
0 1 0 0 1 0 0 0
1 0 1 1 0 1 1 1
+ 1
1 0 1 1 1 0 0 0
Example
Simply invert each bit of given binary number, which will be 01010001.
1 0 1 0 1 1 1 0
0 1 0 1 0 0 0 1
+ 1
0 1 0 1 0 0 1 0
These are examples of converting an eight-bit two's complement number to decimal. To do this, you first
check if the number is negative or positive by looking at the sign bit. If it is positive, simply convert it to
decimal. If it is negative, make it positive by inverting the bits and adding one. Then, convert the result to
decimal. The negative of this number is the value of the original binary.
Interpret 110110112 as a two's complement binary number, and give its decimal equivalent.
1 1 0 1 1 0 1 1
0 0 1 0 0 1 0 0
+ 1
0 0 1 0 0 1 0 1
Since the original number was negative, the final result is -37.