Help language development. Donate to The Perl Foundation
Bits - provide bit related functions
use Bits; # exports "bit", "bits", "bitcnt" say bit(8, 3); # 1000 -> True say bit(7, 3); # 0111 -> False say bits(8); # 1000 -> (3,).Seq say bits(7); # 0111 -> (0,1,2).Seq say bitcnt(8); # 1000 -> 1 say bitcnt(7); # 0111 -> 3
This module exports a number of function to handle bits in unsigned integer values.
sub bit(Int:D value, UInt:D bit --> Bool:D)
Takes a integer value and a bit number and returns whether that bit is set.
sub bits(Int:D value --> Seq:D)
Takes a integer value and returns a
Sequence of the bit numbers that are significant in the value. For negative values, these are the bits that are 0.
sub bitcnt(Int:D value --> Int:D)
Takes a integer value and returns the number of significant bits that are set in the value. For negative values, this is the number of bits that are 0.
Elizabeth Mattijsen [email protected]
Source can be located at: https://github.com/lizmat/Bits . Comments and Pull Requests are welcome.
Copyright 2019 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.