0

I'm struggling to understand how truncation works when converting from unsigned to Two's Complement. Can someone please explain? (my textook uses the example of truncating a 4 bit value to a 3 bit value, and says that -1 becomes -1, but -5 becomes 3).

girlrockingguna
  • 291
  • 1
  • 3
  • 13
  • it depends on if you have unsigned values, signed values, etc...do you have an example? – Bill May 05 '13 at 09:58
  • Without knowing how your text book explains it, what makes you think any explanation here might be any clearer? It is not even clear to me what you mean by "truncation". If the value is unsigned, how can the source be -1 or -5 as in your example - they are both signed values? – Clifford May 05 '13 at 10:06
  • I think @Pascal Cuoq has done well to make some sense of and answer your question, but if that is indeed the answer, this is not a question of "unsigned to two's complement" conversion, but rather one of conversion from a larger two's complement to a smaller two's complement type - in this case 4-bit to 3-bit. Either way, this is not really a "conversion" but merely a reinterpretation of a bit pattern. – Clifford May 05 '13 at 10:34

1 Answers1

7

-1 represented on four binary bits is:

1 1 1 1

(-1 is always represented as all bits 1 in 2's complement).

In your textbook “truncating” is simply used to mean(*) “cutting off the highest-order bit(s)”:

  1 1 1

The result still has all its bits sets so it still represents -1 — This time, the 3-bit 2's complement version of -1.

-5 is represented in 2's complement on 4 bits as:

1 0 1 1

Chopping off the highest-order bit:

  0 1 1

We are left with the 3-bit representation of 3. The reason we could not get -5 any more is that -5's magnitude is too large to fit in a 3-bit format.

Numbers with smaller magnitude, that can be represented with 3 bits, are unchanged when the higher-order bits are chopped off. This is the case for numbers from -4 to 3.

(*) Note that usually “truncating” means keeping the most significant bits and removing the least significant ones, especially in the context of floating-point where the bits with weight less than one are erased when converting to integer by “truncation”. The choice of words in the OP's book is very doubtful, unless the book is not in English and words do not map exactly to English when translated.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • 1
    That makes sense of the rather ambiguous question perhaps, but it is a 4 bit two's complement to 3-bit two's complement conversion (or rather interpretation), not an "unsigned to two's complement conversion". That is perhaps the source of @girlrockingguna's confusion. – Clifford May 05 '13 at 10:29
  • @Clifford I agree with you that the “-5 unsigned” does not make it easy to be sure what is being asked. – Pascal Cuoq May 05 '13 at 10:41
  • I'm not sure truncating is strictly defined as "cutting off the highest-order bit(s)"? At least I tend to see it used to mean cutting off the _lower_ bits (e.g. when working with digital audio). I think that perhaps the word is context-sensitive and might be ambiguous if left unqualified with which bits you're removing. If OP had removed the lower bits, they'd have seen a different result. – underscore_d Nov 29 '15 at 13:26
  • 1
    @underscore_d You are right, both the question and my answer would have to have the vocabulary tightened up to be useful to future visitors. I'm not sure if it's worth it or if it should just be deleted. – Pascal Cuoq Nov 29 '15 at 13:31
  • 1
    @underscore_d I have added a prominent warning. – Pascal Cuoq Nov 29 '15 at 13:36
  • Great, so it wasn't me getting the definition wrong :) [though I'll have to keep searching to find why I'm getting white noise when truncating 2c!] – underscore_d Nov 29 '15 at 13:49