Module Dnsruby::BitMapping
In: lib/dnsruby/bit_mapping.rb

Provides methods for converting between the various representations of a bitmap: number, binary encoded string, array, and sparse array.

Where an array is used to represent bits, the first element (0) will be the low (1) bit and the last bit will be the high bit.

Methods

Public Instance methods

If number is negative, raises an ArgumentError; else does nothing.

Converts a binary string to an array of bit values, e.g. "\x0C" => [1, 1, 0, 0]

Converts from a binary string to a number, e.g. "\x01\x00" => 256

Converts an array of bit values, e.g. [1, 0, 0, 1], to a number, e.g. 9

Converts a number to a binary encoded string, e.g. 256 => "\x01\x00"

Converts a number to an array of bit values, e.g. 9 => [1, 0, 0, 1]

Converts a number to an array of place values, e.g. 9 => [8, 0, 0, 1]

Converts a number to a sparse array containing bit positions that are set/true/1. Note that these are bit positions, e.g. 76543210, and not bit column values such as 128/64/32/16/8/4/2/1.

Converts from a value array to a number, e.g. [8, 0, 0, 1] => 9

Reverses a binary string. Note that it is not enough to reverse the string itself because although the bytes would be reversed, the bits within each byte would not.

Converts an array of bit position numbers to a numeric value, e.g. [0, 2] => 5

[Validate]