Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Easy Way to remember Ranges of

 
Steve Bartholomew
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...Primitive values - any good tips

(eg - byte 8 bits, short 16 bits etc....)

any good websites / refreshers to help with converting bin to hex and so on?

Thanks!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well always remember that the signed primitives have one less positive value than negative.

For SCJP 5.0 you don't need to worry as much about this than say the 1.4 exam.

Mark
 
K Bala
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,

Here is a formula to calculate the value range for primitive data types - byte to long.

Value Range = (-2^n-1) to (2^n-1)-1 where n is the size in bits.

So this is how it works.

Variable Type Size(in bits) Value
byte 8 (-2^7) - 2^7-1 (-128 to 127)
short 16 (-2^15) - 2^15-1(-32768 to 32767)
int 32 (-2^31) - 2^31-1
long 64 (-2^63) - 2^63-1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic