static public byte [ ] shortToBytes ( short v ) { byte [ ] b = new byte [ 2 ] ; int allbits = 255 ; for ( int i = 0 ; i < 2 ; i ++ ) { b [ 1 - i ] = ( byte ) ( ( v & ( allbits << i * 8 ) ) >> i * 8 ) ; } return b ; }
Convert a short to an array of 2 bytes .