# Bit manipulation API

bitmask ( bit -- mask )
  Given a bit number, yield the associated mask. 2 --> $04, 31 --> $80000000

bit? ( n bit -- f )
  Yields whether bit number "bit" is set in "n".

bit1! ( n bit -- n )
  Ensures that bit number "bit" is set in "n".

bit0! ( n bit -- n )
  Ensures that bit number "bit" is unset in "n".

bitsplit ( n bit -- hi lo )
  Split "n" in two "hi" and "lo" part by splitting it at "bit".

  $12345678 4 bitsplit .x spc> .x \ Prints 12345670 00000008

bitflag ( n "name" -- )
  Create a constant "name" with the nth bit set. For example, "3 bitflag FOO"
  is the same as "8 const FOO".

&bit< ( shift sz "name" )
  Compile a new word "name" that performs an "and" on PS top of "sz" bit wide
  and then shifts it left by "shift". Example:

  25 4 &bit< foo<
  42 foo< .x \ Prints $14000000

  The compiled word is significantly faster (through HAL, see doc/hal) than
  "$xx and xx lshift".

&bit> ( shift sz "name" )
  Compile a new word "name" that shifts PS top right by "shift" and then
  performs an "and" on PS top of "sz" bit wide. Example:

  4 6 &bit> foo>
  $12345eaf foo> . \ Prints 42

sex8 ( n -- n )
  Provided that "n" is an 8-bit number, sign-extend it to 32-bit, that is, copy
  b7 to all upper bits.

sex16 ( n -- )
  Same as sex8, but for 16-bit numbers.
