public static byte[] incrementBytes(byte[] value, long amount) {
    byte[] val = value;
    if (val.length < SIZEOF_LONG) {
      // Hopefully this doesn't happen too often.
      byte[] newvalue;
      if (val[0] < 0) {
        newvalue = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 };
      } else {
        newvalue = new byte[SIZEOF_LONG];
      }
      System.arraycopy(val, 0, newvalue, newvalue.length - val.length, val.length);
      val = newvalue;
    } else if (val.length > SIZEOF_LONG) {
      throw new IllegalArgumentException("Increment Bytes - value too big: " + val.length);
    }
    if (amount == 0) return val;
    if (val[0] < 0) {
      return binaryIncrementNeg(val, amount);
    }
    return binaryIncrementPos(val, amount);
  }
Bytewise binary increment/deincrement of long contained in byte array on given amount.
@param value  - array of bytes containing long (length &lt;= SIZEOF_LONG)
@param amount value will be incremented on (deincremented if negative)
@return array of bytes containing incremented long (length == SIZEOF_LONG)
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java