This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes question on primitive type ranges Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "question on primitive type ranges" Watch "question on primitive type ranges" New topic
Author

question on primitive type ranges

Gary Peck
Greenhorn

Joined: Jun 03, 2003
Posts: 15
I understand that for example a byte type contains 8 bits and can hold from -128 to 127. My question is this:
0111 1111 = 127
Why can't a byte store a 1 in the most significant spot(1111 1111)?
I think now that Im looking at it...that this would make it a negative number? What IS the value of 1111 1111?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

Yes, 11111111 is -128. The convention is called "Two's complement arithmetic." See, for example, here for more info.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: question on primitive type ranges
 
Similar Threads
need help
bit representation of negative values
shift operators
shifting
explain me (double)