bit-twiddle

WebJar for bit-twiddle

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

bit-twiddle
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

bit-twiddle
WebJar for bit-twiddle
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mikolalysenko/bit-twiddle

Download bit-twiddle

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/bit-twiddle/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>bit-twiddle</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/bit-twiddle/
implementation 'org.webjars.npm:bit-twiddle:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/bit-twiddle/
implementation ("org.webjars.npm:bit-twiddle:1.0.2")
'org.webjars.npm:bit-twiddle:jar:1.0.2'
<dependency org="org.webjars.npm" name="bit-twiddle" rev="1.0.2">
  <artifact name="bit-twiddle" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='bit-twiddle', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "bit-twiddle" % "1.0.2"
[org.webjars.npm/bit-twiddle "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

bit-twiddle

This is a collection of miscellaneous bit twiddling hacks ported to JavaScript, mostly taken from here:

testling badge

build status

Install

Via npm:

npm install bit-twiddle

API

sign(v)

Computes the sign of the integer v. Returns:

  • -1 if v < 0
  • 0 if v === 0
  • +1 if v > 0

abs(v)

Returns the absolute value of the integer v

min(x,y)

Computes the minimum of integers x and y

max(x,y)

Computes the maximum of integers x and y

isPow2(v)

Returns true if v is a power of 2, otherwise false.

log2(v)

Returns an integer approximation of the log-base 2 of v

log10(v)

Returns log base 10 of v.

popCount(v)

Counts the number of bits set in v

countTrailingZeros(v)

Counts the number of trailing zeros.

nextPow2(v)

Rounds v up to the next power of 2.

prevPow2(v)

Rounds v down to the previous power of 2.

parity(v)

Computes the parity of the bits in v.

reverse(v)

Reverses the bits of v.

interleave2(x,y)

Interleaves a pair of 16 bit integers. Useful for fast quadtree style indexing. (See wiki: http://en.wikipedia.org/wiki/Z-order_curve )

deinterleave2(v, n)

Deinterleaves the bits of v, returns the nth part. If both x and y are 16 bit, then it is true that:

deinterleave2(interleave2(x,y), 0) === x
deinterleave2(interleave2(x,y), 1) === y

interleave3(x,y,z)

Interleaves a triple of 10 bit integers. Useful for fast octree indexing.

deinterleave3(v, n)

Same deal as deinterleave2, only for triples instead of pairs

nextCombination(x)

Returns next combination ordered colexicographically.

Acknowledgements

Code is ported from Sean Eron Anderson's public domain bit twiddling hacks page. http://graphics.stanford.edu/~seander/bithacks.html JavaScript implementation (c) 2013 Mikola Lysenko. MIT License

Versions

Version
1.0.2