static int bytesNeeded(long v){
  if (v < 0) {
    v=~v;
  }
  return ((64 - Long.numberOfLeadingZeros(v)) / 8) + 1;
}

static int bytesNeeded ( long v ) { if ( v < 0 ) { v = ~ v ; } return ( ( 64 - Long . numberOfLeadingZeros ( v ) ) / 8 ) + 1 ; }
return the number of bytes needed to encode the given long . value returned will be > = 1 and < = 8 .
