Java Integer reverseBytes()方法

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

1 语法

public static int reverseBytes(int i)

2 参数

i :这是int值。

3 返回值

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

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Integer reverseBytes()方法
 */
import java.lang.*;

public class IntegerDemo {

   public static void main(String[] args) {

     int i = 170;
     System.out.println("Number = " + i);
    
     /* returns the string representation of the unsigned integer value 
     represented by the argument in binary (base 2) */
     System.out.println("Binary = " + Integer.toBinaryString(i));

     // returns the number of one-bits 
     System.out.println("Number of one bits = " + Integer.bitCount(i)); 
  
     /* returns the value obtained by reversing the bytes in the 
     specified int value */ 
     System.out.println("After reversing = " + Integer.reverseBytes(i));
   }
}

输出结果为:

Number = 170
Binary = 10101010
Number of one bits = 4
After reversing = -1442840576

 

热门文章

优秀文章