aspose file tools*
The moose likes Beginning Java and the fly likes Adding two bytes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding two bytes" Watch "Adding two bytes" New topic
Author

Adding two bytes

Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Check this post.


[My Blog]
All roads lead to JavaRanch
Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
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

Joined: Oct 27, 2005
Posts: 19557
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 383

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


http://plainoldjavaobject.blogspot.in
Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
Thanks everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding two bytes
 
Similar Threads
Mock Exam Question
doubt in Expressions
Why cast int to byte?
Type Conversion doubt
byte + byte = int?