22.214.171.124 represent positive and negative numbers in two's complement and specify the range of n bits.
126.96.36.199 perform subtraction using two's complement
Represent positive and negative numbers in two's complement
Problem. The new car move straight on and use posive speed but when the car move back what speed it has?
If the value of miles on the counter of the car is 000000 and we go back one mile, then the counter will show the value 999999, but we cannot say that we have driven 999999 miles :-)
Signed and unsigned binary numbers.
An unsigned representation of a binary number can only represent positive numbers.
A signed representation can represent both positive and negative numbers.
Two's complement binary works in a similar way to numbers on an analogue counter. Moving the car forwards one give us number 000 001, turn back one - 999 999. It means 999 999 is interpreted as -1.
If in denary 000 000 - 1 = 999 999
What result in binary 0000 0000 - 1?
For signed representation is used sign bit
Question. How represent min and max number of data type shortint
Converting a negative decimal number to binary
Start by working out the positive equivalent of the number, flip all of the bits and add 1.
Converting a negative two's complement binary number to decimal
The same method work the other way. Flip all of the bits and add 1. Then work out the result in decimal using the normal method.
For example, to convert the binary number 1110 0101 to decimal:
Binary substruction using two's complement
Binary substraction is best done by using the negative two's complement number and then adding the second number.
For example, decimal 17 - 14 would be:
The carry on the addition is ignored, and the correct answer is given.
Additionally Addition and Subtraction using 2's complement
|Просмотров: 129 | ||
|Всего комментариев: 0|