public static void binToHex ( byte [ ] bin , int start , int length , StringBuffer hex ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( tc , "binToHex" , new Object [ ] { bin , Integer . valueOf ( start ) , Integer . valueOf ( length ) , hex } ) ; /* Constant for binary to Hex conversion */ final char BIN2HEX [ ] = { ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' } ; int binByte ; for ( int i = start ; i < start + length ; i ++ ) { binByte = bin [ i ] ; /* SibTreat the byte as unsigned */ if ( binByte < 0 ) binByte += 256 ; /* Convert and append each digit */ hex . append ( BIN2HEX [ binByte / 16 ] ) ; hex . append ( BIN2HEX [ binByte % 16 ] ) ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( tc , "binToHex" , hex ) ; }
Converts a binary value held in a byte array into a hex string in the given StringBuffer using exactly two characters per byte of input .