gpt4 book ai didi

java - GetBytes() 返回负数

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:08:33 46 4
gpt4 key购买 nike

*"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() 在字符 'ä' 处返回负数 (-61, () )。

如何获取正常的ascii值?

最佳答案

GetBytes() returns negative number (-61, () ) at the char 'ä'.

getBytes() 将使用平台默认编码,除非您指定了一种编码,您应该这样做。我通常会推荐 UTF-8。例如,在 Java 7 中:

byte[] data = text.getBytes(StandardCharsets.UTF_8);
不幸的是,Java 中的

byte 已签名 - 但您可以认为它只是 8 位。如果你想看到有效的未签名,只需使用:

int unsigned = someByte & 0xff;

How to get the normal ascii value?

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

关于java - GetBytes() 返回负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22575308/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com