public static byte[] hexStringToByteArray(String strA){
  ByteArrayOutputStream result=new ByteArrayOutputStream();
  byte sum=(byte)0x00;
  boolean nextCharIsUpper=true;
  for (int i=0; i < strA.length(); i++) {
    char c=strA.charAt(i);
switch (Character.toUpperCase(c)) {
case '0':
      if (nextCharIsUpper) {
        sum=(byte)0x00;
        nextCharIsUpper=false;
      }
 else {
        sum|=(byte)0x00;
        result.write(sum);
        nextCharIsUpper=true;
      }
    break;
case '1':
  if (nextCharIsUpper) {
    sum=(byte)0x10;
    nextCharIsUpper=false;
  }
 else {
    sum|=(byte)0x01;
    result.write(sum);
    nextCharIsUpper=true;
  }
break;
case '2':
if (nextCharIsUpper) {
sum=(byte)0x20;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x02;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '3':
if (nextCharIsUpper) {
sum=(byte)0x30;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x03;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '4':
if (nextCharIsUpper) {
sum=(byte)0x40;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x04;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '5':
if (nextCharIsUpper) {
sum=(byte)0x50;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x05;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '6':
if (nextCharIsUpper) {
sum=(byte)0x60;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x06;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '7':
if (nextCharIsUpper) {
sum=(byte)0x70;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x07;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '8':
if (nextCharIsUpper) {
sum=(byte)0x80;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x08;
result.write(sum);
nextCharIsUpper=true;
}
break;
case '9':
if (nextCharIsUpper) {
sum=(byte)0x90;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x09;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'A':
if (nextCharIsUpper) {
sum=(byte)0xA0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0A;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'B':
if (nextCharIsUpper) {
sum=(byte)0xB0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0B;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'C':
if (nextCharIsUpper) {
sum=(byte)0xC0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0C;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'D':
if (nextCharIsUpper) {
sum=(byte)0xD0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0D;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'E':
if (nextCharIsUpper) {
sum=(byte)0xE0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0E;
result.write(sum);
nextCharIsUpper=true;
}
break;
case 'F':
if (nextCharIsUpper) {
sum=(byte)0xF0;
nextCharIsUpper=false;
}
 else {
sum|=(byte)0x0F;
result.write(sum);
nextCharIsUpper=true;
}
break;
default :
break;
}
}
if (!nextCharIsUpper) {
throw new RuntimeException("The String did not contain an equal number of hex digits");
}
return result.toByteArray();
}

public static byte [ ] hexStringToByteArray ( String strA ) { ByteArrayOutputStream result = new ByteArrayOutputStream ( ) ; byte sum = ( byte ) 0x00 ; boolean nextCharIsUpper = true ; for ( int i = 0 ; i < strA . length ( ) ; i ++ ) { char c = strA . charAt ( i ) ; switch ( Character . toUpperCase ( c ) ) { case '0' : if ( nextCharIsUpper ) { sum = ( byte ) 0x00 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x00 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '1' : if ( nextCharIsUpper ) { sum = ( byte ) 0x10 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x01 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '2' : if ( nextCharIsUpper ) { sum = ( byte ) 0x20 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x02 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '3' : if ( nextCharIsUpper ) { sum = ( byte ) 0x30 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x03 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '4' : if ( nextCharIsUpper ) { sum = ( byte ) 0x40 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x04 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '5' : if ( nextCharIsUpper ) { sum = ( byte ) 0x50 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x05 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '6' : if ( nextCharIsUpper ) { sum = ( byte ) 0x60 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x06 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '7' : if ( nextCharIsUpper ) { sum = ( byte ) 0x70 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x07 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '8' : if ( nextCharIsUpper ) { sum = ( byte ) 0x80 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x08 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case '9' : if ( nextCharIsUpper ) { sum = ( byte ) 0x90 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x09 ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'A' : if ( nextCharIsUpper ) { sum = ( byte ) 0xA0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0A ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'B' : if ( nextCharIsUpper ) { sum = ( byte ) 0xB0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0B ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'C' : if ( nextCharIsUpper ) { sum = ( byte ) 0xC0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0C ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'D' : if ( nextCharIsUpper ) { sum = ( byte ) 0xD0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0D ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'E' : if ( nextCharIsUpper ) { sum = ( byte ) 0xE0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0E ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; case 'F' : if ( nextCharIsUpper ) { sum = ( byte ) 0xF0 ; nextCharIsUpper = false ; } else { sum |= ( byte ) 0x0F ; result . write ( sum ) ; nextCharIsUpper = true ; } break ; default : break ; } } if ( ! nextCharIsUpper ) { throw new RuntimeException ( "The String did not contain an equal number of hex digits" ) ; } return result . toByteArray ( ) ; }
converts readable hex - string to bytearray
