gpt4 book ai didi

java - TextView::getText() 对于不可见字符返回 -3

转载 作者:行者123 更新时间:2023-12-02 07:48:12 25 4
gpt4 key购买 nike

如果我设置 TextView 字节如下:

byte[] byteArray = { 25, 20, -101 };
TextView encrypted_text = (TextView) findViewById(R.id.encrypted);
encrypted_text.setText(new String(byteArray));

然后我可以检索 25、20,但不能检索 -101 值。对于第三个字符,我总是得到 -3 作为输出:

Log.v(TAG, "3rd byte: "+ (byte) encrypted_text.getText().toString().charAt(2));

附注实际上,所有不可见字符都会返回 -3。

如何从 TextView 取回我的 byteArray?

最佳答案

我知道如何在 TextView 中存储和检索负字节值。首先,我们需要将有符号字节转换为无符号字节。因为在 Java 中所有类型都经过签名,所以我们需要手动执行此操作:

// remove signed bit(32nd), keep value as "next" (127+...) positive byte value
int unsignedValue = 255 - ((int)byteArray[i])&0b1111111;

关于java - TextView::getText() 对于不可见字符返回 -3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562681/

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