So my professor has a question to make a list of all positive and negative numbers that can be represented in Ones', 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, ones' 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?
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,
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).
If the number is positive
If the number is negative
e.g. Take the previous example again
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