This is a computer architecture question given in our college syllabus and i was finding difficulty in solving it. Calculate the range of a 16-bit 2's complement number system for representing both signed and unsigned integers. Please guide me.
Asked
Active
Viewed 4,793 times
2
-
@Brian - now i got this concept, yes it was pretty basic, but at that time i did not know it. The reason why i got confused was because of that 2's complement. what i think max in 2's complement will be 0111....(15 1's) and least will be, 1000....(15 0's) – Avnish Gaur Sep 27 '12 at 17:56
1 Answers
2
For a non negative value, the most significant bit is 0 and the remaining 15 bits represent the value directly.
For a negative value, the most significant bit is 1 and the remaining 15 bits represent the absolute value minus one complemented.
Example for -1:
00000000 00000001 (absolute value)
00000000 00000000 (minus one)
11111111 11111111 (complemented) --> (-1 in 2's complement)
2's complement does not makes sense for unsigned numbers.
For 16 bit unsigned:
Min: 0x0000 --> 0
Max: 0xFFFF --> 65535
For 16 bit signed:
Min: 0x8000 --> -32768
Max: 0x7FFF --> 32767
2's complement is used because it simplifies sums at binary level.
Take these examples:
00000000 00001010 (10 decimal)
+11111111 11111001 (-7 decimal)
-------------------
1 00000000 00000011 (3 decimal) (the leftmost 1 is discarded because overflows the 16 bit sum)
00000000 00001100 (12 decimal)
+11111111 11101001 (-23 decimal)
-------------------
11111111 11110101 (-11 decimal)
Bruno Ferreira
- 4,468
- 2
- 25
- 37
-
2Your ranges are correct, but "A 2's complement number reserves the most significant bit for sign" would imply that 0 (16 0 bits) is a positive number, which is IMO nonsense. It also hints that 1xx is the negative of 0xx (for any 15-bit xx), which is true for sign-magnitude but definitely not for 2's complement. – Wouter van Ooijen Sep 01 '12 at 19:44
-
-
Thanks for the answer, I also studied up at my room and figured it out. Although I have a doubt, that in the hexadecimal representation, (like 0xFFFF) what does 0 represent? that its a positive number? can it be 1 also? – Avnish Gaur Sep 02 '12 at 01:03
-
1@user996851
0x, as far as I know, is just a prefix that means that the number is represented in hexadecimal format. – Bruno Ferreira Sep 02 '12 at 01:05 -
One more thing, suppose i want to load a hex constant into register r0, minimum number of steps is 1 right? if we are not supposed to use pseudo-instructions or assembler directives.. It would be MOV r0, #0xFFFF – Avnish Gaur Sep 02 '12 at 01:24
-
@user996851 I don't know what architecture you are using but taking into account your last question I suppose you are using ARM. I never user ARM devices but I believe you can load a literal like that. – Bruno Ferreira Sep 02 '12 at 01:54
-
1@user996851: You had that question (load a value in a register) closed because you showed no work from your side. There is more to it than a simple MOV. – Wouter van Ooijen Sep 02 '12 at 07:20
-
yea, i figured it out, we can only send 8 bits in one time, so to send a 32 bit signal, we need to send it in 4 parts.. Anyways, thanks for help everyone.. :) – Avnish Gaur Sep 04 '12 at 22:20