posted 5 years ago

If by "bit size" you mean "the number of bits in the representation", a signed integer of N bits can represent from

- 2**(N-1)

to

2**(N-1) - 1

so an 8-bit signed integer can represent from -128 to 127

Java doesn't have unsigned integers; I assume you aren't asking about those.

The answer for floating-point numbers is somewhat more complicated, and in fact I use them so rarely I don't remember them off hand. The ranges themselves are available on many web sites; the calculation of them is a little harder to find.

- 2**(N-1)

to

2**(N-1) - 1

so an 8-bit signed integer can represent from -128 to 127

Java doesn't have unsigned integers; I assume you aren't asking about those.

The answer for floating-point numbers is somewhat more complicated, and in fact I use them so rarely I don't remember them off hand. The ranges themselves are available on many web sites; the calculation of them is a little harder to find.

posted 5 years ago

If you are interested about why the range is what it is, then read about two's complement - that's the format in which computers store integer numbers.

posted 5 years ago

Those figures refer to two’s complement; there are other representations, eg unsigned, excess 128 (for 8 bits) which have a range spanning 2 to the

There is also sign and magnitude which has a range one smaller than that, because it includes 0 and -0.

I have only ever seen two’s complement and unsigned integers used.

Floating-point representations are completely different; Google for IEEE754 for the details, which are not at all easy to understand.

*n*where*n*is the number of bits available. Although the maxima and minima are different, the ranges are exactly the same as two’s complement.`Range = maximum value - minimum value + 1.`It is easy to forget the + 1.There is also sign and magnitude which has a range one smaller than that, because it includes 0 and -0.

I have only ever seen two’s complement and unsigned integers used.

Floating-point representations are completely different; Google for IEEE754 for the details, which are not at all easy to understand.

It is sorta covered in the JavaRanch Style Guide. |