Shared functions for fiddling with bits
Shared functions for fiddling with bits
(->string x)
(byte-copy! dst src)
(byte-copy! dst offset n src)
(byte-copy! dst offset n src src-offset)
Copies the bytes from src to dst
Copies the bytes from src to dst
(bytes= x y)
(extract-rightmost-byte n)
Since bytes are signed in java
Since bytes are signed in java
(possibly-2s-complement-8 n)
If an unsigned byte is greater than 127, it needs to be negated to fit into a signed byte.
Thanks, java, for having a crippled numeric stack.
If an unsigned byte is greater than 127, it needs to be negated to fit into a signed byte. Thanks, java, for having a crippled numeric stack.
(possibly-2s-uncomplement-16 n)
Note that this is specifically for a pair of bytes
Note that this is specifically for a pair of bytes
(possibly-2s-uncomplement-32 n)
Note that this is specifically for a quad-byte
Note that this is specifically for a quad-byte
(possibly-2s-uncomplement-64 n)
Note that this is specifically for an 8 byte sequence
Note that this is specifically for an 8 byte sequence
(possibly-2s-uncomplement-8 n)
Note that this is specifically for a single byte
Note that this is specifically for a single byte
(possibly-2s-uncomplement-n n maximum)
Convert [signed] complemented n into unsigned that fits maximum
Convert [signed] complemented n into unsigned that fits maximum
(secure-mod numerator denominator)
DJB sort-of uses this approach in randommod.
Do not use.
It's significantly slower than ordinary mod
I'm pretty sure its only purpoe in life is that C doesn't support really big numbers.
On lots of platforms, a long long is only 64 bits.
Since we're looking at 256 bits right off the bat, java wins here.
DJB sort-of uses this approach in randommod. Do not use. It's significantly slower than ordinary mod I'm pretty sure its only purpoe in life is that C doesn't support really big numbers. On lots of platforms, a long long is only 64 bits. Since we're looking at 256 bits right off the bat, java wins here.
(sub-byte-array src beg)
(sub-byte-array src beg end)
Return an array that copies a portion of the source
Return an array that copies a portion of the source
(uint-pack! dst index src size)
(uint16-pack x)
(uint16-pack! dst index src)
Sets 2 bytes in dst (starting at offset n) to x
Sets 2 bytes in dst (starting at offset n) to x
(uint16-unpack src)
(uint16-unpack src offset)
Unpack an array of 2 bytes into a 16-bit short
Unpack an array of 2 bytes into a 16-bit short
(uint32-pack! dst index src)
Sets 4 bytes in dst (starting at offset n) to x
Sets 4 bytes in dst (starting at offset n) to x
(uint32-unpack src)
Unpack an array of 32 bytes into a 32-bit long
Unpack an array of 32 bytes into a 32-bit long
(uint64-pack x)
(uint64-pack! x)
(uint64-pack! dst index src)
Sets 8 bytes in dst (starting at offset n) to x
Note that this looks/smells very similar to TweetNaclFast's Box.generateNonce.
But I don't see an obvious way to reverse that, and it's buried inside a class.
So stick with this translation.
Sets 8 bytes in dst (starting at offset n) to x Note that this looks/smells very similar to TweetNaclFast's Box.generateNonce. But I don't see an obvious way to reverse that, and it's buried inside a class. So stick with this translation.
(uint64-unpack src)
Unpack an array of 8 bytes into a 64-bit long
Unpack an array of 8 bytes into a 64-bit long
(zero-out! dst start end)
Shove zeros into the byte-array at dst, from offset start to offset end
Shove zeros into the byte-array at dst, from offset start to offset end
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close