Complete range of values that can be represented in the 2s complement system having N magnitude bits is -2^N to +(2^N-1). Is not this wrong?

Thread Starter

terabaaphoonmein

Joined Jul 19, 2020
121
Lets take a 2 bit magnitude system so total 3 bits.
Then we can represent.
000(+ and -0)
001(+1)
010(+2)
011(+3)
111(-1)
110(-2
101(-3)
So should not it be from +3 to -3 i.e. 2^N-1 to -(2^N-1)?
Also provide me references that I would appreciate very much.
 

drjohsmith

Joined Dec 13, 2021
1,549
Lets take a 2 bit magnitude system so total 3 bits.
Then we can represent.
000(+ and -0)
001(+1)
010(+2)
011(+3)
111(-1)
110(-2
101(-3)
So should not it be from +3 to -3 i.e. 2^N-1 to -(2^N-1)?
Also provide me references that I would appreciate very much.
There are Two standard ways of representing integer numbers in binary
2's compliment and sign / magnitude.. 1s compliment is almost never used.

For 2's compliment, as used in most computer / digital applications
has many advantages, but as it only has one value for zero, there is always one more -ve number than +ve

011 +3
010 +2
001 +1
000 0
111 -1
110 -2
101 -3
100 -4

To invert a 2's compliment number, invert all bits, and add 1

https://www.geeksforgeeks.org/digital-logic/twos-complement/




In signed number format

011 +3
010 +2
001 +1
000 +0
100 -0
101 -1
110 -2
111 -3

As you see, this has same number of states for +ve and -ve
But you end up with two zero values

To invert is just flip the top bit
 

WBahn

Joined Mar 31, 2012
32,703
Lets take a 2 bit magnitude system so total 3 bits.
Then we can represent.
000(+ and -0)
001(+1)
010(+2)
011(+3)
111(-1)
110(-2
101(-3)
Your thread title specifies two's complement, but your example is not for any standard representation. It also isn't complete, since you don't assign a value to the pattern 100. You need to go back and brush up on how two's complement representation works.

Furthermore, 2's complement doesn't have magnitude bits. What we call the "sign bit" really isn't, though it can be used to determine the sign of the value independent of the lower-order bits.

If it had magnitude bits, however, then you could determine the magnitude of the value without knowledge of what the msb was (what is commonly called the sign bit). But you can't. What we call the sign bit has a weight just like all of the other bits, it's just that its weight happens to be negative.

So should not it be from +3 to -3 i.e. 2^N-1 to -(2^N-1)?
If N=3, then 2^N-1 is 7.

You need to revisit order of operations.

Also provide me references that I would appreciate very much.
References for what?

Since this is homework, you should have some kind of text or other study material. What does it say?

Otherwise, have you done any kind of search for two's complement? There are probably hundreds of thousands of sites that cover it. Go do some reading of some of what's out there and then ask specific questions about what is still not clicking.

Here are some questions to consider:

Given an N-bit pattern, how many distinct patterns are there?

How many patterns are needed to represent all of the values, v, where -M ≤ v ≤ +M (where M > 0)?
 

WBahn

Joined Mar 31, 2012
32,703
There are Two standard ways of representing integer numbers in binary
2's compliment and sign / magnitude.. 1s compliment is almost never used.
Ones complement is used by the overwhelming majority of people throughout much of the day. Every IP packet that makes up their network traffic uses it as part of the IP protocol to calculate the IP checksum.

There's another binary integer representation that almost everyone uses every day. Any time you do anything with a floating point value, that value is likely represented per the IEEE-754 standard. That representation involves two integers, the exponent and the significand. The significand uses sign/magnitude, but the exponent uses offset binary (sometimes called biased or excess-K).
 

BobTPH

Joined Jun 5, 2013
11,463
Lets take a 2 bit magnitude system so total 3 bits.
Then we can represent.
000(+ and -0)
001(+1)
010(+2)
011(+3)
111(-1)
110(-2
101(-3)
So should not it be from +3 to -3 i.e. 2^N-1 to -(2^N-1)?
Also provide me references that I would appreciate very much.
Why are you leaving out one of the 8 states?

100 (-4)
 

drjohsmith

Joined Dec 13, 2021
1,549
Ones complement is used by the overwhelming majority of people throughout much of the day. Every IP packet that makes up their network traffic uses it as part of the IP protocol to calculate the IP checksum.

There's another binary integer representation that almost everyone uses every day. Any time you do anything with a floating point value, that value is likely represented per the IEEE-754 standard. That representation involves two integers, the exponent and the significand. The significand uses sign/magnitude, but the exponent uses offset binary (sometimes called biased or excess-K).
to be pedantic ,
the checksum is a positive integer represented by binary,
it is not represented as a signed number.

the same goes for the fractional part of the IEEE floating point number .,
it can never be negative , so its just binary ,

https://en.m.wikipedia.org/wiki/Ones'_complement
https://en.m.wikipedia.org/wiki/Binary_number
 

WBahn

Joined Mar 31, 2012
32,703
to be pedantic ,
the checksum is a positive integer represented by binary,
it is not represented as a signed number.
You might want to tell the authors of the IPv4 protocol that:

Header Checksum: 16 bits

A checksum on the header only. Since some header fields change
(e.g., time to live), this is recomputed and verified at each point
that the internet header is processed.

The checksum algorithm is:

The checksum field is the 16 bit one's complement of the one's
complement sum of all 16 bit words in the header.
For purposes of
computing the checksum, the value of the checksum field is zero.

This is a simple to compute checksum and experimental evidence
indicates it is adequate, but it is provisional and may be replaced
by a CRC procedure, depending on further experience.

the same goes for the fractional part of the IEEE floating point number .,
it can never be negative , so its just binary ,

https://en.m.wikipedia.org/wiki/Ones'_complement
https://en.m.wikipedia.org/wiki/Binary_number
This is, admittedly, a matter of semantics. It would be entirely reasonable to assert that a signed integer represented using sign/magnitude consists of a sign bit and a magnitude portion that can never be negative and is therefore just binary. Or you can say that the entire collection of bits is a signed value. The same is true with a value represented in scientific notation. It can either be thought of as two separate pieces, a sign and a magnitude, with the magnitude further broken into significand and exponent, or it can be thought of as being broken first into a signed significand and an exponent. The end result is the same, and there are conceptual arguments in favor of both views, depending on the focus of the discussion.

I can't find my copy of the original IEEE-754 standard right now, but I wouldn't be surprised if it is written from the viewpoint of splitting off the sign information early and treating the significand as an unsigned value. For their purposes, that's quite reasonable. But it really doesn't matter -- the representation is still based on a sign/magnitude framework in which the sign information and the magnitude information are stored and represented independently and separate from each other.
 

drjohsmith

Joined Dec 13, 2021
1,549
You might want to tell the authors of the IPv4 protocol that:

Header Checksum: 16 bits

A checksum on the header only. Since some header fields change
(e.g., time to live), this is recomputed and verified at each point
that the internet header is processed.

The checksum algorithm is:

The checksum field is the 16 bit one's complement of the one's
complement sum of all 16 bit words in the header.
For purposes of
computing the checksum, the value of the checksum field is zero.

This is a simple to compute checksum and experimental evidence
indicates it is adequate, but it is provisional and may be replaced
by a CRC procedure, depending on further experience.



This is, admittedly, a matter of semantics. It would be entirely reasonable to assert that a signed integer represented using sign/magnitude consists of a sign bit and a magnitude portion that can never be negative and is therefore just binary. Or you can say that the entire collection of bits is a signed value. The same is true with a value represented in scientific notation. It can either be thought of as two separate pieces, a sign and a magnitude, with the magnitude further broken into significand and exponent, or it can be thought of as being broken first into a signed significand and an exponent. The end result is the same, and there are conceptual arguments in favor of both views, depending on the focus of the discussion.

I can't find my copy of the original IEEE-754 standard right now, but I wouldn't be surprised if it is written from the viewpoint of splitting off the sign information early and treating the significand as an unsigned value. For their purposes, that's quite reasonable. But it really doesn't matter -- the representation is still based on a sign/magnitude framework in which the sign information and the magnitude information are stored and represented independently and separate from each other.
I just checked, your right on the check sum, your correct,
 
Top