0

I was wondering if someone can explain to me what happens when we add binary numbers.

Say we have 4 bits, 0b1111 and we add 1 to 0b1111. I think the binary encoding should be 0b10000; however, since there are only 4 bits the bits will change to 0b0000.

I was wondering why this happens, is it because there's not enough space? How would we add 1 to it if 0b1111 was a signed integer?

2
  • this is cause overflow, You cant show the number 8 with 3 bits/4 bit sign Commented May 27, 2016 at 5:38
  • This question may need a chapter to elaborate. If you want to know the ins and outs, check Unsigned and Signed Integers for more explanation. Commented May 30, 2017 at 2:24

1 Answer 1

1

if 0b1111 is an unsigned 4 bit value, with 4 bit storage, it has a value of 15. Adding 1 to it, will give you 16, which cannot be stored in 4 bits. The bits roll over and 0b0000 is stored, giving you a result of 0.

Now, if 0b1111 is a signed 4 bit value, with 4 bit storage. it is generally stored in the two's complement representation. It has a range of -8 to +7. 0b1111 will give you -1. (See here on how to convert.) Adding one to that gives you 0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.