One's twos compliment 8 bit signed magnitude, in binary - binary

So this was one of the questions in my textbooks, we haven't got there yet but i'm interested in how this all works,
For the first bit here, my understanding of one's complement is you flip so where there are 1's you put 0's and 0's you put ones. This has to be 8 bit so i added a zero to the binary at the start
Therefre 01001001
Write down the following binary representations of +73:
8-bit unsigned: 01001001
8-bit signed-magnitude: 01001001
8-bit one's complement: 10110110
8-bit two's complement: 10110111
8-bit excess-128: 10110111
These are the answers I came up with, but i'm fairly certain i did them wrongly. Any clarification on this?
Secondly, how the heck to I do it with a negative so -73, the binary is just -01001001 so I assume that is the signed, do you do the same technique as above( assuming i have got them correct)
8-bit signed-magnitude: -01001001
8-bit one's complement:
8-bit two's complement:
8-bit excess-128:
Thanks in advance for any help

+73 is 01001001 in all the representations you named except excess-128. In excess-128 its 11001001 (add 128 to it). Sign magnitude, one's complement, and two's complement are all the same for positive numbers and only differ for negative numbers. The value of -73 in those representations is:
8-bit sign magnitude 11001001
8-bit one's complement 10110110
8-bit two's complement 10110111
8-bit excess-128 00110111
the one's complement 'flip all bits' is how you negate a number in one's complement notation. So if you have n, to get -n you flip all the bits.
'flip all bits and add 1' is how you negate a number in two's complement.
Both one's complement and two's complement have one odd value. For one's complement that's -0 (all bits set), which is really the same as 0 -- or you can treat it as invalid and special case negating 0. For two's complement, that's -2^(n-1) -- -128 for 8-bit -- which is a number that negates to itself due to overflow.

Related

16-bit two's complement number

The question is
What are two's complement numbers of the following 16-bit numbers?
1.0x3f9d
My answer is:
0011111110011101 in binary because 0x3f9d is a positive number.
However, some people said that the answer is:
1100000001100011
I am confusing because 1100000001100011 is a negative number. Which one is the right answer?
3F9Dh is a positive number, equal to 0011 1111 1001 1101 binary. It only makes sense to speak of two's complement when a number is negative.
You might be confusing the term two's complement presentation (of a number) with the algorithm "calculate two's complement of x". If you would calculate the two's complement of 3F9Dh, you would indeed end up with 1100 0000 0110 0011.
In C you could do this calculation as
(uint16_t)~0x3F9D + 1
which is equivalent to
(uint16_t)-0x3F9D
(assuming two's complement CPU and not some exotic nonsense CPU)

Binary 16 bit signed 2's complement system?

For an assignment the question is "What is the range of positive numbers and negative numbers represented by a 16-bit signed 2's compliment system? I've tried looking it up and I can't figure it out.

I want to find 2's complement of 0000

I want to design a hardware which will give 2's complement of input 4-bit binary number. But i stuck at very first input: 0000.Because the method i generally use to find 2's complement is to first find 1's complement of binary number and then adding 1 into it.But if I do same with 0000, then it will give me 5-bit number 10000. that is the problem.
You have to cut off the upper bits if you're working with an n-bit value. The two's complement of the four-bit 0000 is the last four bits of 10000, or 0000. Otherwise the ones' complement of 100 would be:
1111111111...ad infinitum...1111111011
rather than the correct 011.
That (the cutting off of extraneous bits) makes sense since the negation of zero is zero (though that could be arguable for ones' complement or sign-magnitude, where -0 is a distinct possibility).
If you design hardware, see hardware circuits for produce 4-bit complement number.

Two's Complement of a number and its negative number difference?

So i was told that two's complement is usually to used to find complement of a number and I used it only to complement positive numbers (i.e positve --> negative conversion) however I just got an example in book which asks me the following :
Express 23, -23, and -9 in 8-bit binary two’s Complement
form
now what does that mean? 23 means -23 in binary and -23 means 23 ?
sorta confused over there
2's complement is used to represent negative numbers, which in turn, can be used to do subtraction.
23 = 00010111b
To get -23 (2's complement of 23), flip all the bits, and add 1:
11101000b + 1
=11101001b (-23)
-9 is the 2's complement of 9. 9 is
00001001b
So -9 is
11110111b (Flipping and add +1)
See also here
The representation of positive numbers in 2's complement is same as the unsigned representation. Things start to change when negative representation comes into play. So, in general, for given w bits, the numbers that can be represented in 2's complement are -2^(w-1)-1 to 2^(w-1) with the w bit being the signed bit. So since you have 8 bits you can represent numbers from -128 to 127. The 8th bit will be the signed bit, with 0 being positive and 1 representing negative.
For any positive representation of a number in binary 2's complement N the negative counterpart -N is pretty simple to find, just invert the bits, and add one. Example:
7 in 2's complement is 0111, inverting these bits gives: 1000, adding one gives 1001, which is -7 in 2's complement! Hope this helps!

Advantage of 2's complement over 1's complement?

What is the advantage of 2's complement over 1's complement in negative number representation in binary number system? How does it affect the range of values stored in a certain bit representation of number in binary system?
The primary advantage of two's complement over one's complement is that two's complement only has one value for zero. One's complement has a "positive" zero and a "negative" zero.
Next, to add numbers using one's complement you have to first do binary addition, then add in an end-around carry value.
Two's complement has only one value for zero, and doesn't require carry values.
You also asked how the range of values stored are affected. Consider an eight-bit integer value, the following are your minimum and maximum values:
Notation Min Max
========== ==== ====
Unsigned: 0 255
One's Comp: -127 +127
Two's Comp: -128 +127
References:
http://en.wikipedia.org/wiki/Signed_number_representations
http://en.wikipedia.org/wiki/Ones%27_complement
http://en.wikipedia.org/wiki/Two%27s_complement
The major advantages are:
In 1's there is a -0 (11111111) and a +0 (00000000), i.e two value for the same 0. On the other hand, in 2's complement, there is only one value for 0 (00000000). This is because
+0 --> 00000000
and
-0 --> 00000000 --> 11111111 + 1 --> 00000000
While doing arithmetic operations like addition or subtraction using 1's, we have to add an extra carry bit, i.e 1 to the result to get the correct answer, e.g.:
+1(00000001)
+
-1(11111110)
-----------------
= (11111111)
but the correct answer is 0. In order to get 0 we have to add a carry
bit 1 to the result (11111111 + 1 = 00000000).
In 2's complement, the result doesn't have to be modified:
+1(00000001)
+
-1(11111111)
-----------------
= 1 00000000
Negative integers :
2's complement makes sense to be used for negative integers. 1's complement is just a computation technique which might be helpful to evaluate 2's complement. The real (defeated) rival of 2's complement was the sign-magnitude representation for negative integers.
No overflow : 1's complement has no special usage for negative integers. 2's complement makes sense because it can be used in natural addition and subtraction arithmetic without any need to change the bits. Providing that no overflow occurs, the sign bit of the result is just the right value. The bit number promotion in this notation is straight forward, for example, to promote an 8-bit signed integer to 16, we could simply repeat the sign bit of integer value in the high byte of it.
Sign magnitude : On the contrary, the sign-magnitude notation is just the way that human uses to represent negative integers. The bit number promotion and addition subtraction arithmetic is a bit mess with this notation.
Advantages of Two’s Complement #1
In Two’s Complement representation, the value zero is
uniquely represented by having all bits set to zero:
**
Advantages of Two’s Complement #2
**
When you perform an arithmetic operation (for example,
addition, subtraction, multiplication, division) on two
signed integers in Two’s Complement representation, you
can use
exactly the same method
as if you had two
unsigned integers (that is, nonnegative integers with no sign
bit) ...
EXCEPT
, you throw away the high carry (or the high
borrow
for subtraction)
Advantages of Two’s Complement #3
This property of Two’s Complement representation is so
incredibly handy that virtually every general
purpose
computer available today uses Two’s Complement.
Why? Because, with Two’s Complement, we don’t need
special algorithms
(and therefore extra circuitry) for
arithmetic operations that involve negative values.
Another major advantage of Two's complement over signed bit representation is 2's complement representation is easy to manipulate in hardware
2s complement isn't for representing a negative number it's an inverse.
Means you can do A + B' (where B' is the 2s complement of B) to give A - B, means you can do everything with an adder and not need a substracter