Character.reverseBytes() in Java with examples
Last Updated :
13 Jun, 2018
java.lang.Character.reverseBytes() is a built-in method in java which returns the value obtained by reversing the order of the bytes in the specified char value.
Syntax:
public static char reverseBytes(char ch)
Parameter: The function accepts one mandatory parameter ch which signifies the character whose order of bytes is to be reversed.
Returns: This method returns the value obtained by reversing (or, equivalently, swapping) the bytes in the specified char value.
Below programs illustrate the java.lang.Character.reverseBytes() function:
Program 1:
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
char c1 = '\u4d00' ;
char c2 = Character.reverseBytes(c1);
System.out.println( "Reversing bytes on " + c1 + " gives " + c2);
}
}
|
Output:
Reversing bytes on ? gives M
Program 2:
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
char c1 = '9' ;
char c2 = Character.reverseBytes(c1);
System.out.println( "Reversing bytes on " + c1 + " gives " + c2);
c1 = '7' ;
c2 = Character.reverseBytes(c1);
System.out.println( "Reversing bytes on " + c1 + " gives " + c2);
}
}
|
Output:
Reversing bytes on 9 gives ?
Reversing bytes on 7 gives ?
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...