Java字符文字值与getNumericValue() [英] Java Character literals value with getNumericValue()

查看:371
本文介绍了Java字符文字值与getNumericValue()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我会为大小写文字取得相同的结果?例如:

Why do I get the same results for both upper- and lowercase literals? For instance:

char ch1 = 'A';
char ch2 = 'a';
char ch3 = 'Z';
char ch4 = 'z';

print("ch1 -- > " + Integer.toBinaryString(Character.getNumericValue(ch1)));
print("ch2 -- > " + Integer.toBinaryString(Character.getNumericValue(ch2)));
print("ch3 -- > " + Integer.toBinaryString(Character.getNumericValue(ch3)));
print("ch4 -- > " + Integer.toBinaryString(Character.getNumericValue(ch4)));

结果我得到:

ch1 -- > 1010
ch2 -- > 1010
ch3 -- > 100011
ch4 -- > 100011

并没有真正看到'A'和'a'之间的区别。即使我使用UTF形式的字符文字(\\\A代表'A'和\\\a代表'a'),我也得到相同的结果。

And don't really see the difference between 'A' and 'a'. Even if I use character literals in UTF form (\u0041 for 'A' and \u0061 for 'a') I do get the same results.

推荐答案

它的行为与

It's behaving exactly as documented:


字母AZ大写('\\\A'至'\\\Z'),小写'\\\a'到'\\\z')和全宽度变量('\\\A'到'\\\Z'和'\\\a'到'\\\z')形式的数值从10到35 。

The letters A-Z in their uppercase ('\u0041' through '\u005A'), lowercase ('\u0061' through '\u007A'), and full width variant ('\uFF21' through '\uFF3A' and '\uFF41' through '\uFF5A') forms have numeric values from 10 through 35.

基本上这意味着当解析hex(比如说)时, 0xfa == 0xFA

Basically this means that when parsing hex (say), 0xfa == 0xFA, as you'd expect.

我希望在使用像base64这样的东西时,情况非常重要。

I'd only expect case to matter when using something like base64.

这篇关于Java字符文字值与getNumericValue()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆