byte to int Java

byte to int Java


After knowing the Java rules of Data Type Casting (Type Conversion), let us cast byte to int. The byte takes 1 byte of memory and int takes 4 bytes of memory. Assignment 1 byte value to 4 bytes is done implicitly by the JVM.

byte –> short –> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse requires explicit casting.

Example:

Following program on byte to int explains the syntax of implicit casting in Java.


byte to int
Output screenshot of byte to int Java

1 byte value b1 is assigned to 4 bytes i1 and is type casted implicitly. This is known as implicit casting or widening conversion.

View all for 65 types of Conversions

Pass your comments and suggestions of how far this is helpful to you and also for the improvement of this tutorial "byte to int Java"

2 thoughts on “byte to int Java

  1. Yuvi

    Hi sir,
    Thanks for providing java concepts with detailed explanation. Here my question is: The range of java byte is -128 to 127. If we given the value like byte b=129; we are getting an error called “possible loss of precision”. But at the same time it allows the below code:
    int a=143;
    byte b=(byte) a;
    How it allows byte range more than 127?

Leave a Reply

Your email address will not be published. Required fields are marked *