A simple bitarray library for nim.
git clone https://github.com/YesDrX/bitarray.git
cd bitarray
nimble install
or
nimble install nimbitarray
import bitarray
when isMainModule:
var
a = newBitsArray(70)
b = newBitsArray(70)
echo " a = ",a
echo " b = ",b
echo "set bits ..."
a.setBits(0,1,2,3,4,69)
b.setBits(6,7,8,9,65)
echo " a = ",a
echo " b = ",b
echo "a & b = ", a & b
echo "a | b = ", a | b
echo "a ^ b = ", a ^ b
echo " ~a = ", ~a
echo "a.shl(1) =",a.shl(1)
echo "a.shl(2) =",a.shl(2)
echo "a.shl(3) =",a.shl(3)
echo "a.shl(69)=",a.shl(69)
echo "a.shr(1) =",a.shr(1)
echo "a.shr(2) =",a.shr(2)
echo "a.shr(3) =",a.shr(3)
echo "a.shr(69)=",a.shr(69)
echo "basic types"
echo (-7).toBitsArray
echo (7).toBitsArray
echo (-1.555).toBitsArray
echo (1.555).toBitsArray
echo (-7.int16).toBitsArray
echo (7.int16).toBitsArray
a = 0000000000000000000000000000000000000000000000000000000000000000000000
b = 0000000000000000000000000000000000000000000000000000000000000000000000
set bits ...
set [0,1,2,3,4,69]-th bit of a
a = 1111100000000000000000000000000000000000000000000000000000000000000001
set [6,7,8,9,65]-th bit of a
b = 0000001111000000000000000000000000000000000000000000000000000000010000
a & b = 0000000000000000000000000000000000000000000000000000000000000000000000
a | b = 1111101111000000000000000000000000000000000000000000000000000000010001
a ^ b = 1111101111000000000000000000000000000000000000000000000000000000010001
~a = 0000011111111111111111111111111111111111111111111111111111111111111110
a.shl(1) =1111000000000000000000000000000000000000000000000000000000000000000010
a.shl(2) =1110000000000000000000000000000000000000000000000000000000000000000100
a.shl(3) =1100000000000000000000000000000000000000000000000000000000000000001000
a.shl(69)=1000000000000000000000000000000000000000000000000000000000000000000000
a.shr(1) =0111110000000000000000000000000000000000000000000000000000000000000000
a.shr(2) =0011111000000000000000000000000000000000000000000000000000000000000000
a.shr(3) =0001111100000000000000000000000000000000000000000000000000000000000000
a.shr(69)=0000000000000000000000000000000000000000000000000000000000000000000001
expand a to 100 bits: 1111100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000
127.uint32.toBitsArray = 11111110000000000000000000000000
127.uint32.toBitsArray.reverseBits = 00000000000000000000000001111111
127.uint32.toBitsArray.reverseBits.reverseBits = 11111110000000000000000000000000
(uint32.high-3).toBitsArray = 00111111111111111111111111111111
(uint32.high-3).toBitsArray.reverseBits = 11111111111111111111111111111100
bitarray's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.