syed sadath

Greenhorn

Posts: 2

syed sadath

Greenhorn

Posts: 2

posted 1 year ago

- 1

suppose if a variable is of n bits.then most significant bit is the sign bit leaving (n-1) bits for representing number.so total combinations possible are 2^(n-1)(for negative value representation bound is -2^(n-1)),now after negative value their comes 0 and positive numbers so excluding one combination for 0 leaves 2^(n-1)-1 combination and thus entails positive bound to be 2^(n-1)-1.

in your case for 16 bit

negative bound( -2 ^ ( 16-1 ) )--->zero--->( 2 ^ (16-1) -1)positive bound

hope it helps!

kind regards,

praveen

in your case for 16 bit

negative bound( -2 ^ ( 16-1 ) )--->zero--->( 2 ^ (16-1) -1)positive bound

hope it helps!

kind regards,

praveen

Try to enjoy your work while doing it,it will Automatically convert in Hard Work...

Campbell Ritchie

Marshal

Posts: 56520

172

posted 1 year ago

In fact it is a complementary number where exactly half the range is negative and half the range non‑negative. For negative numbers you get the equivalent of subtracting |

You get sign bits in IEEE754 floating‑point numbers; the

Lost of people are told that the leftmost bit in an integer is a sign bit, but that is incorrect. The easiest way to regard it is as equivalent to −(2³¹) but that is not really accurate.syed sadath wrote:. . . first bit(msb) is for sign(+,-) . . .

In fact it is a complementary number where exactly half the range is negative and half the range non‑negative. For negative numbers you get the equivalent of subtracting |

*n*| from 2³². Even though 2³² doesn't actually exist as an

`int`.

You get sign bits in IEEE754 floating‑point numbers; the

*n*− 1 bits on the right are exactly the same for

*x*and −

*x*.

Campbell Ritchie

Marshal

Posts: 56520

172

posted 1 year ago

OK, well you should say that. Accuracy is very important in programming, and a

The answer is actually very straightforward:

1. The number of possible values that can be held by a binary field of n bits is 2ⁿ, which is an

2. If the value has to be

3. Except for one thing: What about 0?

You could have two of them: +0 and −0, and then you'd have a span of -2ⁿ⁻¹−1...+2ⁿ⁻¹−1 - indeed an older form of binary representation called 1's complement did precisely that.

The problem then is that arithmetic logic becomes more difficult, especially at the circuit board level (explained in the link), so most computers these days use 2's complement, which has only one '0' value. And since we don't normally think of 0 as being "negative", it makes sense to make it non-negative.

It also allows 0 to be represented by "all 0's", which has other useful properties - not the least of which being visual.

However, that means removing 1 value from the "positive" side to represent 0 itself, and hence the imbalance.

HIH

Winston

- 2

syed sadath wrote:Actually it is short i.e, 2^15-1 to -2^15(-32768 to 32767)...

OK, well you should say that. Accuracy is very important in programming, and a

`short`is NOT an

`int`... nor indeed a

`, which is a different animal altogether.`

**S**hortThe answer is actually very straightforward:

1. The number of possible values that can be held by a binary field of n bits is 2ⁿ, which is an

__even__number.

2. If the value has to be

*signed*- as both

`short`and

`int`are in Java - then those values should probably be divided by 2, giving 2ⁿ⁻¹ values of each "sign".

3. Except for one thing: What about 0?

You could have two of them: +0 and −0, and then you'd have a span of -2ⁿ⁻¹−1...+2ⁿ⁻¹−1 - indeed an older form of binary representation called 1's complement did precisely that.

The problem then is that arithmetic logic becomes more difficult, especially at the circuit board level (explained in the link), so most computers these days use 2's complement, which has only one '0' value. And since we don't normally think of 0 as being "negative", it makes sense to make it non-negative.

It also allows 0 to be represented by "all 0's", which has other useful properties - not the least of which being visual.

However, that means removing 1 value from the "positive" side to represent 0 itself, and hence the imbalance.

HIH

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |