問題描述
我正在嘗試將包含二進制值(例如 000010001010011)的字符串轉換為十六進制值.(453)
I am trying to translate a String that contains a binary value (e.g. 000010001010011) to it's Hex value.(453)
我一直在嘗試幾個選項,但大多數情況下我得到了每個單獨字符的轉換值.(0=30 1=31)
I've been trying several options, but mostly I get a converted value of each individual character. (0=30 1=31)
我有一個函數,它通過非數學方式將我的輸入轉換為二進制代碼,但通過一系列if, else if"語句.(這些值不計算,因為它們不是標準的.)二進制代碼包含在變量字符串binOutput"中
I have a function that translates my input to binary code through a non-mathematical way, but through a series of "if, else if" statements. (the values are not calculated, because they are not standard.) The binary code is contained in a variable String "binOutput"
我目前有這樣的事情:
String bin = Integer.toHexString(Integer.parseInt(binOutput));
但這根本不起作用.
推薦答案
嘗試使用 Integer.parseInt(binOutput, 2)
代替 Integer.parseInt(binOutput)
這篇關于將包含二進制值的字符串轉換為十六進制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!