Jump to content
Kat Rollo

Converting Decimal to Two's-Complement

Recommended Posts

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:

error.png

 

I am only using the converter to check my answers. Our professor will not credit work without solution.

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)?

I would love to understand this concept. Thank you.

 

Share this post


Link to post
Share on other sites

Yes it is, but I understand now. :)

 

2^5 = 32

The signed decimal range is -16 to +15, which is 32 integers (including 0).

Therefore, +16 is out of range.

 

Also, positive values must always be represented with a leading 0. Negative values must be represented with a leading 1.

However, the 5-bit limit prevents the addition of another bit.

The (10000) base 2 is the two's-complement of -16 in decimal.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the explanation kathy025. I've tried to find out a solution, but without success. I was still thinking about it but then I've found your same answer, that is far better than what I was thinking. So, mystery solved and thank you again for curing my headache. Cheers :D

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×