Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Integer.reverseBytes() method is used to return the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value.

Syntax

public static int reverseBytes(int i)

Parameters

i Specify the value whose bytes are to be reversed.

Return Value

Returns the value obtained by reversing the bytes in the specified int value.

Exception

NA.

Example:

In the below example, the java.lang.Integer.reverseBytes() method is used to return the value obtained by reversing the bytes in the given int value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a int value
    int x = 100; 

    //printing value of x, its binary representation
    //and reversing the bytes
    System.out.println("The values of x is: " + x);
    System.out.print("The binary representation of x is: ");
    System.out.println(Integer.toBinaryString(x));
    System.out.print("After reversing : ");
    System.out.println(Integer.reverseBytes(x));
  }
}

The output of the above code will be:

The values of x is: 100
The binary representation of x is: 1100100
After reversing : 1677721600

❮ Java.lang - Integer