Last active
December 11, 2015 23:29
-
-
Save 0guzhan/4677493 to your computer and use it in GitHub Desktop.
This class provides utility methods for converting char to its decimal-octal-hexadecimal equivalent integer values in String representations. CONSOLE> Decimal: 97
Octal: 0141
Hex: \u0061
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blog.oguzhan.charutil; | |
/** | |
* This class provides utility methods for converting char | |
* to its decimal-octal-hexadecimal equivalent integer values in String representations. | |
* | |
* @author oguzhan.acargil | |
* */ | |
public class CharUtil { | |
public static String toHexASCII(char c) { | |
return "\\u" + String.format("%04x", (int)c); | |
} | |
public static String toOctalASCII(char c) { | |
return String.format("%04o", (int)c); | |
} | |
public static String toDecimalASCII(char c) { | |
return String.valueOf((int)c); | |
} | |
public static void main(String[] args) { | |
System.out.println("Decimal: " + toDecimalASCII('a')); | |
System.out.println("Octal: " + toOctalASCII('a')); | |
System.out.println("Hex: " + toHexASCII('a')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment