Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question on primitive type ranges  RSS feed

 
Gary Peck
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, 11111111 is -128. The convention is called "Two's complement arithmetic." See, for example, here for more info.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!