Java Integer.reverseBytes() – Examples

In this tutorial, we will learn about Java Integer.reverseBytes() method, and learn how to use this method to get an integer by reversing the order of bytes of a given integer, with the help of examples.

reverseBytes(int i)

Integer.reverseBytes() returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.

ADVERTISEMENT

Syntax

The syntax of reverseBytes() method with integer as parameter is

Integer.reverseBytes(int i)

where

ParameterDescription
iThe integer value whose order of bytes has to be reversed.

Returns

The method returns value of type int.

Example 1 – reverseBytes(int)

In this example, we will

Java Program

public class Example {
	public static void main(String[] args){
		int i = 12340;
		int result = Integer.reverse(i);
		System.out.println("Result of reverse("+i+") = " + result);
	}
}

Output

Result of reverse(12340) = 738983936

Conclusion

In this Java Tutorial, we have learnt the syntax of Java Integer.reverseBytes() method, and also how to use this method with the help of Java example programs.