It's not a secret anymore!
The moose likes Beginning Java and the fly likes last bit in data type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "last bit in data type" Watch "last bit in data type" New topic

last bit in data type

nada saif

Joined: Nov 14, 2009
Posts: 8
Hi ,

I am confused about how to define the limits of data in examples we say byte starts from -128 and stops at 127

How we can use -128 as i know the last bit is just for sign ???



Henry Wong

Joined: Sep 28, 2004
Posts: 20535

The representation is not as simple as 7 bits for the value and one bit for the sign (independently). There is one bit for the sign, but the eight bits needs to be evaluated together to get the overall value.

Basically, Java uses two complement to represent bytes, shorts, ints, and longs.'s_complement


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: last bit in data type
It's not a secret anymore!