Java Long reverseBytes()方法

java.lang.Long.reverseBytes() 方法返回通过反转指定long值的二进制补码表示的字节的顺序而获得的值。

1 语法

public static long reverseBytes(long i)

2 参数

i :这是long 值。

3 返回值

此方法返回通过反转指定long值的字节数得到的值。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Long reverseBytes()方法
 */
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

 

热门文章

优秀文章