Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

last bit in data type

 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic