public static long getMaxUnsignedValueOnBytes ( final int width ) { if ( width < 0 || width > 8 ) { throw new IllegalArgumentException ( "Width must be from 1 to 8 bytes: " + width ) ; } if ( width < 8 ) { return ( ( long ) 1 << width * Byte . SIZE ) - 1 ; } else { return Long . MAX_VALUE ; } }
Simple helper to calculate the max value for any width of long from 0 to 8 bytes .