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
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 16695
    
  19

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: last bit in data type
 
Similar Threads
Binary conversion help
Together ControlCentre is resource hungry?
Binary representation of -128
not cleared Primitive type?
Question regarding Byte.MAX_VALUE