Java.lang.Long.reverseBytes() 方法
描述
java.lang.Long.reverseBytes() 方法返回指定 long 值的二进制补码表示中的字节顺序颠倒得到的值。
声明
以下是 java.lang.Long.reverseBytes() 方法的声明。
public static long reverseBytes(long i)
参数
i − 这是 long 值。
返回值
该方法返回指定long值中的字节取反得到的值。
异常
NA
示例
下面的例子展示了 java.lang.Long.reverseBytes() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class LongDemo {
public static void main(String[] args) {
long l = 210;
System.out.println("Number = " + l);
/* returns the string representation of the unsigned long value
represented by the argument in binary (base 2) */
System.out.println("Binary = " + Long.toBinaryString(l));
/* returns the value obtained by reversing the bytes in the specified
long value */
System.out.println("After reversing = " + Long.reverseBytes(l));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Number = 210 Binary = 11010010 After reversing = -3314649325744685056

