java.lang.Character.reverseBytes()是java中的内置方法,该方法返回通过反转指定char值中的字节顺序而获得的值。
用法:
public static char reverseBytes(char ch)
参数:该函数接受一个强制性参数ch,该参数表示字符的字节顺序要颠倒。
返回值:此方法返回通过反转(或等效地交换)指定char值中的字节而获得的值。
以下程序说明了java.lang.Character.reverseBytes()函数:
示例1:
// Java program to demonstrate the
// Character.reverseBytes() when a
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// char whose byte order is to be reversed
char c1 = '\u4d00';
char c2 = Character.reverseBytes(c1);
// prints the reversed bytes
System.out.println("Reversing bytes on " + c1 + " gives " + c2);
}
}
输出:
Reversing bytes on ? gives M
示例2:
// Java program to demonstrate the
// Character.reverseBytes() when a
// number is passed
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// char whose byte order is to be reversed
char c1 = '9';
char c2 = Character.reverseBytes(c1);
// prints the reversed bytes
System.out.println("Reversing bytes on " + c1 + " gives " + c2);
c1 = '7';
c2 = Character.reverseBytes(c1);
// prints the reversed bytes
System.out.println("Reversing bytes on " + c1 + " gives " + c2);
}
}
输出:
Reversing bytes on 9 gives ?
Reversing bytes on 7 gives ?