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

Adding two bytes

 
Nelson Sam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to add two bytes.But I am getting "Possible loss of precision" Error.
Also tell me how int and byte different from each other.And when to use byte.
Thanks

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this post.
 
Nelson Sam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Christophe Verré.

Also tell me how int and byte different from each other.And when to use byte.


Now I need answer for above quoted text
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int takes up 32 bits (4 bytes) and has a range of -(2^31) to (2^31)-1 (inclusive). byte takes up 8 bits (1 byte ) and has a range of -128 to 127 (inclusive). byte is useful if you only need this limited range.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's like ... int is the standard computation datatype for decimal numbers in java so every short is automatically converted to an int before computation ... please see about widening and narrowing conversions
 
Nelson Sam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic