Question

Instructions: Convert these decimal numbers to 5-bit 2's-complement form, if possible. If not possible, explain why this is so.

(16) base 10

According to the online converter:

From what I understand,

If decimal is positive:

  • STEP 1: Convert magnitude to binary.
  • STEP 2: Pad 0's to desired bitsize.

If decimal is negative:

  • STEP 1: Convert magnitude to binary.
  • STEP 2: Pad 0's to desired bitsize.
  • STEP 3: Invert bits to achieve 1's-complement.
  • STEP 4: Add 1 to achieve 2's-complement.

Since 16 is positive, I simply converted it to binary by repeated division yielding (10000) base 2.

I no longer padded 0's since it is already 5-bits (containing 5 digits).

Can somebody explain to me why the online converter is returning an error (which also I strongly believe is the correct answer)?

Was it helpful?

Solution

With 5 bits you can represent up to 2^5 different numbers, since you want negative and positive numbers the range is -16 to +15.

so you get error since 16 is out of the range for 5 bits. Change to 6 bits and it should work

OTHER TIPS

You need 6 bits to represent +16 since the value 10000 represents -16.

Best way to visualize is -
00000-0
00001-1
00010-2
....
01111-15
10000-(-)16
10001-(-)15
....
Try taking the 2's complement of 10000, you should get the value 16 in binary

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top