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.



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

Integer.reverseBytes(int i)


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


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);


Result of reverse(12340) = 738983936


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.