public static long reverseByteOrder ( long value , int numOfLowerBytesToInvert ) { if ( numOfLowerBytesToInvert < 1 || numOfLowerBytesToInvert > 8 ) { throw new IllegalArgumentException ( "Wrong number of bytes [" + numOfLowerBytesToInvert + ' ' ) ; } long result = 0 ; int offsetInResult = ( numOfLowerBytesToInvert - 1 ) * 8 ; while ( numOfLowerBytesToInvert -- > 0 ) { final long thebyte = value & 0xFF ; value >>>= 8 ; result |= ( thebyte << offsetInResult ) ; offsetInResult -= 8 ; } return result ; }
Revert order for defined number of bytes in a value .