private static byte[] binaryIncrementPos(byte[] value, long amount) {
    long amo = amount;
    int sign = 1;
    if (amount < 0) {
      amo = -amount;
      sign = -1;
    }
    for (int i = 0; i < value.length; i++) {
      int cur = ((int) amo % 256) * sign;
      amo = (amo >> 8);
      int val = value[value.length - i - 1] & 0x0ff;
      int total = val + cur;
      if (total > 255) {
        amo += sign;
        total %= 256;
      } else if (total < 0) {
        amo -= sign;
      }
      value[value.length - i - 1] = (byte) total;
      if (amo == 0) return value;
    }
    return value;
  }
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