aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "last bit in data type" Watch "last bit in data type" New topic
Author

last bit in data type

nada saif
Greenhorn

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 ???


Best,

Nada

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

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.

http://en.wikipedia.org/wiki/Two's_complement

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: last bit in data type