java字母的值,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)));

As results I get:

ch1 -- > 1010

ch2 -- > 1010

ch3 -- > 100011

ch4 -- > 100011

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:

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.

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值