bin :extract-bits ( mixed $VALUE , int $LO , int $HI )
Extracts bits from the provided value, starting at $LO lowest bit and going towards the $HI lowest bit. Both bounds are included in the resulting value. If the bounds span across more than 64bits, the bits closer to the higher bound will be returned.
Endianness is taken into account when moving across bytes. Extracting the 0th bit from an int value should yield the same result as taking modulo 2.
Note that this function was intended to be used primarily with integers, so its behaviour with other types may be confusing.
asdf
, the f
is considered bits 0-7.)# :extract-bits example :set &num i0 :write s'Gibe number plox: ' :read &num # Default print omits leading zeros :writeln s'binary: ' :set b0 $num # Print every single bit in loop, including leading zeros :write s' bits: ' :set &idx i63 !while :ge $idx i0 :write :extract-bits $num $idx $idx :sub &idx i1 !done :writeln
wikipage modified on 2014/0916/2155