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 ?
相關用法
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java.util.concurrent.Phaser用法及代碼示例
- Java Java.util.concurrent.RecursiveTask用法及代碼示例
- Java Java.util.function.BiPredicate用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java.util.function.IntPredicate用法及代碼示例
- Java Java.util.function.DoublePredicate用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.reverseBytes() in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。