         (recur (inc i)
                (->
                  (aget ^bytes data (+ offset i))
-                 (long)
-                 (bit-and 0xFF)
                  (as-> b (if (neg? b) (+ b 256) b))
                  (bit-shift-left (- 56 (* i 8)))
                  (+ value)))
         ; Unflip sign bit.
-        (bit-xor value Long/MIN_VALUE)))))
+        (flip-long-sign value)))))
 
 
 (alter-meta! #'->LongLexicoder assoc :private true)

  (encode*
    [_ value]
    ; Flip sign bit so that positive values sort after negative values.
    (let [lexed (bit-xor (long value) Long/MIN_VALUE)
          data (byte-array 8)]
      (dotimes [i 8]
        (->
          lexed
          (bit-shift-right (- 56 (* i 8)))
          (bit-and 0xFF)
          (as-> b (if (< 127 b) (- b 256) b))
          (->> (aset-byte data i))))
      data))


;; ## Long Lexicoder

(defn- flip-long-sign
  "Flip the sign bit on a long value."
  ^long
  [^long x]
  (bit-xor x Long/MIN_VALUE))


(defn- get-long-byte
  "Return the `i`th byte in a long, where 0 gives the least significant byte."
  [l i]
  (bit-and 0xFF (bit-shift-right l (* i 8))))


(defrecord LongLexicoder
  []

