瀏覽單個文章
公不
*停權中*
 

加入日期: Dec 2010
文章: 341
引用:
作者Jiun Yu
public class Test
{
public static void main(String args[])
{
String a = "1234567890ABCDEF";
int b[] = hexstr2array(a, 4);

for(int c: b)
System.out.printf("%d ", c);
System.out.println();
}

public static int[] hexstr2array(String input, int length)
{
int[] output = new int[length];

for(int i = 0; i < length; i++)
if(i < input.length() / 2)
output[i] = Integer.parseInt(input.substring(i*4, i*4+4), 16);
else
output[i] = 0;

return output;
}
}

改完之後還是看不懂你這個函數的用途

感覺 JavaScript 那個版本也有問題,你要什麼功能直接說出來,這樣大家比較好改



後來找到問題了

是substr的問題

JAVA 與javascript 在語法上這邊不同

改用int ss = Integer.parseInt(input.substring((i*2),(i*2+2)),16);

就可以了

謝謝
 
舊 2014-06-18, 08:55 PM #12
回應時引用此文章
公不離線中