Reslove :
"Hello~
World!a1,B2,c3,D4,E5,f6,0xA7,0xb8,0xc9,0x1a,2B,3c,4D,0E,F0"
Result:
data=A1
data=B2
data=C3
data=D4
data=E5
data=F6
data=A7
data=B8
data=C9
data=1A
data=2B
data=3C
data=4D
data=0E
data=F0
String s = "Hello~\nWorld!";
System.out.println(s);
s += "a1,B2,c3,D4,E5,f6,0xA7,0xb8,0xc9,0x1a,2B,3c,4D,0E,F0";
System.out.println(s);
if(s.contains(",")){
String[] sAry = s.split(",");
for(String sTemp:sAry){
byte[] bAry = sTemp.getBytes();
byte[] bChar = new byte[2];
int wIdx = 0;
for(byte bTemp:bAry){
if(bTemp>=0x30 && bTemp<=0x39){
bChar[wIdx] = (byte) (bTemp & 0x0F);
wIdx++;
}
else if(bTemp>=0x41 && bTemp<=0x46){
bChar[wIdx] = (byte) (bTemp - 55);
wIdx++;
}
else if(bTemp>=0x61 && bTemp<=0x66){
bChar[wIdx] = (byte) (bTemp - 87);
wIdx++;
}
else{
wIdx=0;
}
if(wIdx==2){
wIdx=0;
byte bData= (byte) (((bChar[0]<<4) & 0xF0) | (bChar[1] & 0xF));
System.out.println("data=" + String.format("%02X", bData));
}
}
}
}
沒有留言:
張貼留言