static public int shortToBytes ( short s , byte [ ] buffer , int index ) { int length = 2 ; for ( int i = 0 ; i < length ; i ++ ) { buffer [ index + length - i - 1 ] = ( byte ) ( s >> ( i * 8 ) ) ; } return length ; }
This function converts a short into its corresponding byte format and inserts it into the specified buffer at the specified index .