com.jamesratzlaff:bit-manip

Library for bitwise manipulations in arrays

Лицензия

Лицензия

Группа

Группа

com.jamesratzlaff
Идентификатор

Идентификатор

bit-manip
Последняя версия

Последняя версия

2019.04.03
Дата

Дата

Тип

Тип

jar
Описание

Описание

com.jamesratzlaff:bit-manip
Library for bitwise manipulations in arrays
Ссылка на сайт

Ссылка на сайт

https://github.com/jamesratzlaff/bit-manip
Система контроля версий

Система контроля версий

http://github.com/jamesratzlaff/bit-manip/tree/master

Скачать bit-manip

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
com.jamesratzlaff : byte-functions jar 2019.04.01

Модули Проекта

Данный проект не имеет модулей.

bit-manip

Library for bitwise manipulations over arrays

Examples

Cyclic Shifter

//Given an array or (buffer) of bytes:
byte[] bytes =new byte[]{0b10000001,0b00011000,0b00000111};//100000010001100000000111
//Then invoking a bitwise cyclic right shift 2
Bitwise.CyclicShifter.Using.aByteArray(bytes,2);
//the contents of bytes is now 
//{0b11100000,0b010001100,0b0000000}                         111000000100011000000001
//Invoking a bitwise cyclic left shift 2
Bitwise.CyclicShifter.Using.aByteArray(bytes,-2);
//bytes is back to {0b10000001,0b00011000,0b0000111};        100000010001100000000111
//Then invoking a bitwise cyclic right shift 9
Bitwise.CyclicShifter.Using.aByteArray(bytes,9);
//the contents of bytes will be 
//{0b00000011,0b11000000,0b10001100}                         000000111100000010001100

There is also the method Bitwise.CyclicShifter.Using.aByteBuffer implemented for you as well as a generic constructor new CyclicShifter<T>(ToIntFunction<T> lengthGetter, ObjIntToByteFunction<T> getAtIndex, ObjIntByteConsumer<T> setAtIndex) to easily use whatever kind of byte container you please.

At the core all of the shifting and carrying is done using bitwise operators, therefore it runs pretty darn fast. It could be faster using concrete object interaction instead of method references.

Boundless buffer operations

Another object you may find useful is a CyclicByteBuffer which can be used to do operations over arrays smaller or larger than itself. A use of this object can be found in the Bitwise.Util.doOperation(byte[],IntBinaryOperator,byte...) method.

byte[] bytes =new byte[]{0b10000001,0b00011000,0b00000111};//100000010001100000000111
//Let's XOR these bytes with {0b11111111,0b00000000}
Util.doOperation(bytes, (a, b)->(a^b),(byte)-1,(byte)0);  
//the contents of bytes will now be
//{0b01111110,0b00011000,0b11111000}                         011111100001100011111000

Версии библиотеки

Версия
2019.04.03