Since all integers and longs are signed in the JVM, this makes the high order bit awkward to work with in Clojure. Unlike Java, all integral numbers are assumed to be long, so there is no special syntax to indicate this. And when numbers get large enough, they automatically roll over into BigInt values.
Consequently, even though Java can say:
jshell> 0xAAAAAAAAAAAAAAAAL
$1 ==> -1
Clojure does not have this option of indicating that number is a long (and hence negative because of the most significant bit):
user=> 0xAAAAAAAAAAAAAAAA
12297829382473034410N
(Note: the N indicates a BigInt value)
So we need to use the 2s complement form, and negate the value:
Since all integers and longs are signed in the JVM, this makes the high order bit awkward to work with in Clojure. Unlike Java, all integral numbers are assumed to be
long
, so there is no special syntax to indicate this. And when numbers get large enough, they automatically roll over intoBigInt
values.Consequently, even though Java can say:
Clojure does not have this option of indicating that number is a long (and hence negative because of the most significant bit):
(Note: the
N
indicates a BigInt value)So we need to use the 2s complement form, and negate the value: