加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – GetBytes()返回负数

发布时间:2020-12-15 02:52:41 所属栏目:Java 来源:网络整理
导读:*"H?tten Hüte ein ? im Namen,w?ren sie m?glicherweise keine Hüte mehr,sondern H?te." 72 -61 -92 116 116 101 ...* GetBytes()在char’?’返回负数(-61,()). 如何获得正常的ascii值? 解决方法 GetBytes() returns negative number (-61,() ) at the
*"H?tten Hüte ein ? im Namen,w?ren sie m?glicherweise keine Hüte mehr,sondern H?te."
 72  -61  -92  116  116  101  ...*

GetBytes()在char’?’返回负数(-61,()).

如何获得正常的ascii值?

解决方法

GetBytes() returns negative number (-61,() ) at the char ‘?’.

除非您指定编码,否则getBytes()将使用平台默认编码.我会正常推荐UTF-8.例如,在Java 7中:

byte[] data = text.getBytes(StandardCharsets.UTF_8);

遗憾的是,Java中的字节已经签名 – 但您可以将其视为仅为8位.如果你想看到有效的无符号,只需使用:

int unsigned = someByte & 0xff;

How to get the normal ascii value?

ASCII中不存在该字符.所有ASCII字符都在U 0000到U 007F范围内.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读