Skip to content

Utilities for working with binary data and bit manipulation in Dart.

License

Notifications You must be signed in to change notification settings

A-Babin/binary

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binary

Utilities for working with binary data and bit manipulation in Dart.

Pub Build Status Coverage Status documentation

NOTE: Unless otherwise noted, all functionality is based around treating bits as little endian, that is in a 32-bit integer the leftmost bit is 31 and the rightmost bit is 0

Overview

This library supports an Integral data type for fluent bit manipulation:

print(uint8.toBinaryPadded(196)); // '11000100'

Because of Dart's ability to do advanced inlining in both the Dart VM and dart2js, this library should perform well and be extremely easy to use for most use cases. For example, it's used in an arm7_tdmi emulator.

Usage

This library has a combination of top-level methods, and instance methods of pre-defined Integral data types (see below). For example there are two ways to clear (set to 0) a bit:

// Sets the 0th bit in an (int) bits to 0
bits = clearBit(bits, 0)

However, this will not do range validation. Use Integral#clearBit:

// Sets the 0th bit in a uint32 to 0.
// In dev-mode, if either bits or `n` is out of range it throws.
bits = uint32.clearBit(bits, 0);

Integral data types

  • bit
  • int4
  • int8
  • int16
  • int32
  • int64
  • int128
  • uint4
  • uint8
  • uint16
  • uint32
  • uint64
  • uint128

Learning more

See the dartdocs for more about the API.

About

Utilities for working with binary data and bit manipulation in Dart.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 97.4%
  • Shell 2.6%