2's complement of binary numbers and registers

  • Thread starter Thread starter vysero
  • Start date Start date
  • Tags Tags
    Binary Numbers
Click For Summary

Discussion Overview

The discussion revolves around the representation of 2's complement numbers in larger registers, specifically focusing on how to maintain the same value when inserting a 2's complement number into an 8-bit or larger register. Participants explore potential pitfalls and methods for extending binary representations.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant inquires about inserting a 2's complement number into a larger register and expresses concern about potential pitfalls.
  • Another participant suggests that padding the number with leading zeros is a valid approach for inserting a 3-bit number into an 8-bit register.
  • A different participant raises confusion regarding the representation of negative numbers, questioning whether to use leading zeros or extend the sign bit.
  • It is noted that -1 in an 8-bit register is represented as 11111111, prompting a request for a general method to represent any number in larger registers.
  • One participant explains that to represent a negative number like 110 in larger registers, one should extend the most significant bit, providing examples for 8-bit, 16-bit, and 32-bit representations.
  • Further elaboration includes how adding certain values to these representations results in specific bit patterns, although the implications of these additions are not fully resolved.

Areas of Agreement / Disagreement

Participants express differing views on how to handle the representation of negative numbers in larger registers, indicating that there is no consensus on the best approach. Some agree on the method of padding with zeros, while others emphasize the importance of extending the sign bit.

Contextual Notes

There are unresolved assumptions regarding the handling of negative numbers and the implications of extending bits in various register sizes. The discussion does not clarify the mathematical steps involved in the conversion process.

vysero
Messages
134
Reaction score
0

Homework Statement



I want to know how to insert a 2's complement number into a larger register and keep the same value. I would like to know of some pitfalls that I might run into using a generalized method, if any.

Homework Equations

The Attempt at a Solution



If I have say 1 in a 3 bit binary system, 001 and I take the 2's complement of the number I will get 111 or -1 in a 3 bit binary system. Let's say I want to put that number: 111, into an 8 bit register. Can I simple pad the number with leading zeros: 00000111?
 
Physics news on Phys.org
vysero said:
Lets say I want to put that number: 111, into an 8 bit register. Can I simple pad the number with leading zeros: 00000111?

Yes. I don't know what else you could do with those extra 5 bits other than set them to 0.
 
Well I was a bit confused because it is a negative number. So I was not sure if it should be 00000111 or 10000111.
 
Ah, I see. -1 in an eight bit register is 11111111. You should have asked simply, "how do I represent -1 in an 8 binary bit register?"
 
Well I would like how to know how to represent any number in such a way. Say my number is 010. If I take the two's complement of the number then I get 110 which is -6. How can I represent 110 in an eight bit register or a 16 bit register and so on.
 
vysero said:
How can I represent 110 in an eight bit register or a 16 bit register and so on.
Just extend the most significant bit.
As 8 bits: 1111 1110
As 16 bits: 1111 1111 1111 1110
As 32 bits: 1111 1111 1111 1111 1111 1111 1111 1110
And so on.
If you add 2 (or 102) to of these numbers you'll get 0 in bits 0 through 7 for the first number, 0 in bits 0 through 15 for the second number, and 0 in bits 0 through 31 for the third number. Bit 8 will be 1 in the first number, bit 16 will be 1 in the second number, and bit 32 will be 1 in the third number, but these bits aren't in an 8-bit number, a 16-bit number, or a 32-bit number, respectively.

These additions show that -2 + 2 = 0, at least as far as 8-, 16-, or 32-bit addition are concerned.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
622
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K