Liking cljdoc? Tell your friends :D

frereth.cp.shared.bit-twiddling

Shared functions for fiddling with bits

Shared functions for fiddling with bits
raw docstring

->stringclj

(->string x)

byte-copy!clj

(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
raw docstring

bytes=clj

(bytes= x y)

extract-rightmost-byteclj

(extract-rightmost-byte n)

Since bytes are signed in java

Since bytes are signed in java
raw docstring

possibly-2s-complement-8clj

(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.
raw docstring

possibly-2s-uncomplement-16clj

(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
raw docstring

possibly-2s-uncomplement-32clj

(possibly-2s-uncomplement-32 n)

Note that this is specifically for a quad-byte

Note that this is specifically for a quad-byte
raw docstring

possibly-2s-uncomplement-64clj

(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
raw docstring

possibly-2s-uncomplement-8clj

(possibly-2s-uncomplement-8 n)

Note that this is specifically for a single byte

Note that this is specifically for a single byte
raw docstring

possibly-2s-uncomplement-nclj

(possibly-2s-uncomplement-n n maximum)

Convert [signed] complemented n into unsigned that fits maximum

Convert [signed] complemented n into unsigned that fits maximum
raw docstring

secure-modclj

(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.
raw docstring

sub-byte-arrayclj

(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
raw docstring

uint-pack!clj

(uint-pack! dst index src size)

uint16-packclj

(uint16-pack x)

uint16-pack!clj

(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
raw docstring

uint16-unpackclj

(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
raw docstring

uint32-pack!clj

(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
raw docstring

uint32-unpackclj

(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
raw docstring

uint64-packclj

(uint64-pack x)

uint64-pack!clj

(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.
raw docstring

uint64-unpackclj

(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
raw docstring

zero-out!clj

(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
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close