簡體   English   中英

如何將長二進制字符串轉換為字符

[英]how convert long binary string to character

我有二進制字符串xlxr

xl = "11110101011100001001011010011100"
xr = "01100101111100011000011000101011"

我想添加xlxr並將此二進制字符串轉換為8個字符(1個字符= 8位)。 您能幫我獲得此代碼嗎?

String Chippertext = "";   
char nextChar;

for(int i = 0; i <= chippertext.length()-8; i += 8) //this is a little tricky.  we want [0, 7], [9, 16], etc
{
    nextChar = (char)Integer.parseInt(chippertext.substring(i, i+8), 2);
    Chippertext += nextChar;
}
Thasil.setText(Chippertext);

我已經嘗試過此代碼,但是該字符與ascii表上的字符不同。

您不能使用char來表示字節數組的數據,因為有些值不等於“ char”。

最好的解決方案是將每個字節值打印為十進制,十六進制或二進制值。

暫無
暫無

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

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