Skip to content

Instantly share code, notes, and snippets.

@favila
Created March 10, 2016 23:14
Show Gist options
  • Save favila/f75c2cd69ef4b9eb7104 to your computer and use it in GitHub Desktop.
Save favila/f75c2cd69ef4b9eb7104 to your computer and use it in GitHub Desktop.
Basic code pattern to get signed hex literal (for java) from an unsigned hex literal
(defn signed-literal [^String unsigned-hex-str]
(let [s (-> (Long/parseUnsignedLong unsigned-hex-str 16)
(Long/toString 16))]
(if (.startsWith s "-")
(str "-0x" (subs s 1))
(str "0x" s))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment