Giter VIP home page Giter VIP logo

bitarray's Introduction

nimble MIT

bitarray

A simple bitarray library for nim.

Installation

git clone https://github.com/YesDrX/bitarray.git
cd bitarray
nimble install

or

nimble install nimbitarray

Example

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

Contributors

yesdrx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.