16-bit two's complement number - binary

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)

Related

-3 + -3 = -2 in two's complement

using 4-bit numbers calculating -3 + -3 in two's complement, my calculation yields -2.
3 in binary is 0011
making both one's complement by flipping all the digits since both are negative
1100 && 1100
adding one to them, since we are using two's complement
1101 + 1101 =
11010
first one is overflow, and are tossed away in two's complement. So are left with 1010, which is minus two in decimal. Can someone explain what is done wrong in this process?
EDIT
My problem seems more specifically how to interpret the result of a two's complement calculation. I treat the result as following:
The result is 1010.
In my world, the first bit is a sign bit, indicating that the number is negative.
The following 0 means there is 0 of -4's
the following 1 means there is 1 of -2's
the following 0 means there is 0 of -1's
therefore, I interpret it like the result is -2
The result is correct, you just interpreted it wrong. When you perform arithmetic on numbers in two's complement, the result is also two's complement. So the conversion from negative to positive is done the same way as the conversion of the original numbers from positive to negative.
Given the 4-bit binary value 1010, first flip the bits for one's complement to get 0101, then add 1 for two's complement to get 0110.
0110 is 6, so 1010 is -6.
first one is overflow
If, as you imply here, you are restricting your storage to a single nybble, then with two's complement, you can represent values in the range -8 to 7.
-2 would then be 0b1110, which is not what you have. -6 is indeed 0b1010, which is the correct sum.

Does the most significant bit of a Two's Complement number indicate its sign?

I was converting -15 to Two's complement -
15 in binary = 1111
Flip bits and add 1 = 0001
However I also thought that the leftmost digit of a two's complement number indicates whether it represents a positive (0) or negative (1) number? Need some help understanding this

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.

Using Hexadecimal to represent -1(10 in two's complement on 9bits

I'm using two's complement and -1(decimal) is converted to 1111 1111(TwoCom) on eigth bits. The first bit says that the number is negative and when I convert to hex I receive a FF by result.
Is correct?
But I need to know how I can represent -1 (decimal) in hex on 9 bits.
I guess that this would be 1FF ... but I'm not sure.
Any help?
A two's complement number is defined as a 1's complement number + 1. So if you have 9 bits available, and you original number is decimal 1, i.e. 000000001 binary, the 1's complement is 111111110 binary, and the 2's complement is 111111111 binary, which represents -1 decimal.
So, you are right, this is 1FF hex.

One's twos compliment 8 bit signed magnitude, in 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.