簡體   English   中英

字符串與字節數組到字節

[英]String with byte array to byte

我有:

字符串鍵 = "0x64, 0xC, -90, 0x77, 0x2B, -113, 0xD, 0x69, -111, 0x76, 0x11, 0x35, -68, -110, -106, -81"

它已經是保存在共享首選項中的十六進制字節數組。 我只需要像下面這樣。

byte[] input_key = new byte[]{ key }

請注意,有負數。

把實際的解析留給你去發現,這就是我在評論中描述的:

String[] sNums = key.split(","); // Mind that the elements will still contain whitespace!

byte[] bNums = new byte[sNums.length];
for( int i = 0; i < bNums.length; i++ )
{
    if( sNums[i].trim().startsWith("0x") )
    {
       bNums[i] = [insert hex parsing here]
    }
    else
    {
       bNums[i] = [insert decimal parsing here]
    }
}

效率不高也不優雅,但如果解析正確,可能會起作用。

劇透:鮑里斯實際上已經破壞了十六進制解析(將鼠標指向黃色字段 vv )

Integer.valueOf(s,16).byteValue()

從那里開始,您肯定可以弄清楚十進制解析。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM