Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isn't .NET's integer just simply based on two's complement system?

Tags:

c#

.net

vb.net

MSDN:

Int32 values are represented in 31 bits, with the thirty-second bit used as a sign bit. Positive values are represented by using sign-and-magnitude representation. Negative values are in two's complement representation.

Isn't it true that the representation of positive values using sign-and-magnitude system is identical to the representation of positive values using two's complement system?

So shouldn't it have been rewritten as: "Int32 values (regardless of positive or negative) are represented in two's complement representation",

Or am I misunderstanding something?

like image 898
Pacerier Avatar asked May 18 '12 02:05

Pacerier


People also ask

Why do we use 2's complement system over other systems?

2's complement makes sense because it can be used in natural addition and subtraction arithmetic without any need to change the bits. Providing that no overflow occurs, the sign bit of the result is just the right value. we prefered 2's value because in this complement we do not require any carry value or extra 1.

What is 2's complement integer?

A two's-complement number system encodes positive and negative numbers in a binary number representation. The weight of each bit is a power of two, except for the most significant bit, whose weight is the negative of the corresponding power of two. The value w of an N-bit integer.

How many integers can be represented with twos complement?

Like unsigned numbers, N-bit two's complement numbers represent one of 2N possible values. However the values are split between positive and negative numbers. For example, a 4-bit unsigned number represents 16 values: 0 to 15. A 4-bit two's complement number also represents 16 values: −8 to 7.

Is a 32 bit signed two's complement integer?

Understanding RepresentationBy default, integers int are signed 32 bits long, represented in two's complement, which means that it has the following limits: 0000 0000 0000 0000 0000 0000 0000 0000 represents 0 ; 0111 1111 1111 1111 1111 1111 1111 1111 represents 2,147,483,647 (2ˆ31−1);


1 Answers

Yes, you are correct. They should have said it uses a two's complement system, and then given the definition about using 31 bits and, rather than explaining negatives as "two's complement", just explain the bit representation for negatives. Then give their warning about bitwise operators.

like image 58
Keith Nicholas Avatar answered Oct 19 '22 01:10

Keith Nicholas