如何在 Java 中将字符从字母字符转换为十六进制数字?如果有人知道 Java 中的任何内置方法可以完成这项工作,或者您有自己的方法,您能帮忙吗?
How do I convert a char from an alphabetical character to hexadecimal number in Java? If any one knows any built-in methods in Java that does the job or if you have your own method, could you please help?
另外,如何将十六进制转换为二进制?
Also, how would I convert from hex to binary?
你可以从char转换成hex字符串.
You can convert from char to hex string.
char ch =
String hex = String.format("%04x", (int) ch);
要读取十六进制并转换为二进制,您可以这样做
To read hex and convert to binary you can do
int num = Integer.parseInt(text, 16);
String bin = Integer.toString(num, 2);
这篇关于如何在Java中将字符从字母字符转换为十六进制数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)