Positive and Negative Integers

Positive and Negative Integers

Positive and Negative Integers

The ones complement of a binary string is formed by replacing 0s by 1s and 1s by 0s.

The twos complement of a binary integer is formed by finding the 1s complement of the number and adding 1 to it.

Worked questions

1- Find the ones complement and twos complement of 000101101

To find the ones complement replace 0 by 1, 1 by 0

Ones complement of 000101101 = 111010010

Twos complement of 000101101 = Ones complement + 1

                                                             = 111010010+

                                                                                  1

                                                               111010011

Answer: Ones complement is 111010010; twos complement is 111010011

2- Find the eight-bit twos complement of 110100

Make up to eight bits by adding Os on the left: 00110100

Ones complement = 11001011

Twos complement = Ones complement + 1

                                   = 11001011 +

                                                         1

Answer: Twos complement = 11001100

                                                    11001100

METHODS OF STORING INTEGERS

There are several methods of storing integers in a computer so that positive and negative numbers are represented. Often the bit at the left of the string indicates whether the number is positive or negative. This bit is called the sign bit:

Sign-and-magnitude method

The sign bit is I for negative, 0 for positive. The size of the number is shown in the remaining bits.

Twos complement method

The sign bit is 1 for negative, 0 for positive. For positive numbers the remaining bits show the size of the number. For negative numbers the twos complement of the number is shown.

Worked question

Express the binary integers (a) 1011 (b) -11011 in sign-and-magnitude and in twos complement form as they would appear in an eight-bit location.

(a) In sign-and-magnitude form 1011 would be 00001011

In twos complement form 1011 would be 00001011

(b) In sign-and-magnitude form -11011--110011011

In twos complement form:

Extend to eight bits 11011_00011011

Find ones complement _11100100

Add 1 _11100101

Note: Positive numbers are the same for both methods but negative numbers are different.

CONVERTING TWOS COMPLEMENT NEGATIVE INTEGERS TO DECIMAL

Method

Use the same method as that for positive integers . However, treat the sign bit as a negative number.

1- Write powers of 2 above the digits of the number. Start at the right-hand end. That is write ... 64 32 16 8 4 2 1 (as many as necessary).

2- Write down the powers of 2 which are above a 1 in the number. Add them up counting the one over the sign bit as negative.

Worked question

111011 is a negative number in twos complement form. Find its value as a decimal number.

- 32 16 8 4 2 1

    1  1   1 0 1 1

Number = -32+ 16+8+2+1

= -32+27

Answer: Number represented is -5

Labels: