2
votes

So my professor has a question to make a list of all positive and negative numbers that can be represented in One's, two's complements, and sign magnitude:

Using 4 bit numbers, for example (5)10 = ( 0101)2 Write all positive numbers and all negative numbers that can be represented with four bits in sign-magnitude, one’s complement, and two’s complement.

Now, I am not looking for the answer just clarification.

  • for sign magnitude, the first bit represents the sign of the number. so in the example provided, negative five is -5= (1101), The ones complement = (0101) the twos complement (1010)
  • Sign magnitude only allows for three bits to show number and one for the sign (the leading bit from right to left.) This would mean that we only have 8 combinations. so that is numbers from 0-7 and -0- (-6) Ones and twos we have 16? so 0-15 and -0-(-15)

can someone explain this question better?

1
Format your question better please.xrisk

1 Answers

8
votes

Here's a brief description about all the three representation techniques you've mentioned.

Sign and Magnitude Representation

In this representation, we can represent numbers in any number of bits (powers of 2). There are two parts in the representation. Sign and Magnitude, as the name implies.

If we want to represent a number in n number of bits,

  • the first bit always represents the sign of the number. i.e. 0 for a positive number and 1 for a negative number.
  • the remaining bits (n-1) represent the magnitude of the number in Binary.

e.g. If you want to represent +25 and -25 using 8 bits: (+25)10 = 0011001 and (-25)10 = 10011001

Complement

Since Binary number system has only 2 digits (0 and 1), the complement of one digit is the other. i.e. the complement of 0 is 1 and vice versa.

One's Complement

In this representation, there is no specific bit to represent the sign, but the MSB (Most Significant Bit) can be used to determine the sign of the number. i.e. MSB is 0 if the number is positive and 1 if the number is negative. Binary numbers are used and also a specific bit size is used. (e.g. 8, 16, 32, etc. bits).

  1. If the number is positive

    • Convert the number to binary
    • Set the number to specific bit size
  2. If the number is negative

    • Convert the number to binary
    • Set the number to specific bit size
    • Get the complement of that value

e.g. Take the previous example again

  • (+25)10
    • Convert the number to binary -> (11001)2
    • Set the number to specific bit size -> (0001 1001)
  • (-25)10
    • Convert the number to binary -> (11001)2
    • Set the number to specific bit size -> (0001 1001)
    • Get the complement of that value -> (1110 0110)

Two's Complement

This representation technique is very much similar to One's Complement Representation. The main difference is that when the number is negative, 1 is added to the LSB (Least Significant Bit) after getting the complement.

e.g. Let us take the same example

  • (+25)10
    • Convert the number to binary -> (11001)2
    • Set the number to specific bit size -> (0001 1001)
  • (-25)10
    • Convert the number to binary -> (11001)2
    • Set the number to specific bit size -> (0001 1001)
    • Get the complement of that value -> (1110 0110)
    • Add 1 to LSB -> (1110 0110) + 1 = (1110 0111)