2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								! Copyright (C) 2008 Doug Coleman.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								! See http://factorcode.org/license.txt for BSD license.  
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								USING:  assocs  help.markup  help.syntax  math  sequences  kernel  ;
  
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								IN:  math.bitwise  
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  bitfield  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values { "values..."  "a series of objects"  } { "bitspec"  "an array"  } { "n"  integer  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Constructs an integer from a series of values on the stack together with a bit field specifier, which is an array whose elements have one of the following shapes:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $list
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { { $snippet "{ constant shift }"  } " - the resulting bit field is bitwise or'd with "  { $snippet "constant"  } " shifted to the right by "  { $snippet "shift"  } " bits"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { { $snippet "{ word shift }"  } " - the resulting bit field is bitwise or'd with "  { $snippet "word"  } " applied to the top of the stack; the result is shifted to the right by "  { $snippet "shift"  } " bits"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { { $snippet "shift"  } " - the resulting bit field is bitwise or'd with the top of the stack; the result is shifted to the right by "  { $snippet "shift"  } " bits"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"The bit field specifier is processed left to right, so stack values should be supplied in reverse order."  } 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "Consider the following specification:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $list
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { "bits 0-10 are set to the value of "  { $snippet "x"  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { "bits 11-14 are set to the value of "  { $snippet "y"  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { "bit 15 is always on"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { "bits 16-20 are set to the value of "  { $snippet "fooify"  } " applied to "  { $snippet "z"  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "Such a bit field construction can be specified with a word like the following:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ": baz-bitfield ( x y z -- n )" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    {" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "        { fooify 16 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "        { 1 15 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "        11" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "        0" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    } ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  bits  
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "m"  integer  } { "n"  integer  } { "m'"  integer  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Keep only n bits from the integer m."  }
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $example "USING: math.bitwise prettyprint ;"  "0x123abcdef 16 bits .h"  "cdef"  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-09-19 17:54:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  bit-range  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values { "x"  integer  } { "high"  integer  } { "low"  integer  } { "y"  integer  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Extract a range of bits from an integer, inclusive of each boundary."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $example "USING: math.bitwise prettyprint ;"  "0b1100 3 2 bit-range .b"  "11"  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								HELP:  bitroll  
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $values { "x"  integer  } { "s"  "a shift integer"  } { "w"  "a wrap integer"  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Roll n by s bits to the left, wrapping around after w bits."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;"  "1 -1 32 bitroll .b"  "10000000000000000000000000000000"  }
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;"  "0xffff0000 8 32 bitroll .h"  "ff0000ff"  }
							 
						 
					
						
							
								
									
										
										
										
											2008-09-05 20:29:14 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  bit-clear?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "?"  "a boolean"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns "  { $link t  } " if the nth bit is set to zero."  }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0xff 8 bit-clear? ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "t" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0xff 7 bit-clear? ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "f" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ bit?  bit-clear? set-bit clear-bit } related-words
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  bit-count  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "obj"  object  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Returns the number of set bits as an object. This word only works on non-negative integers or objects that can be represented as a byte-array."  }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0xf0 bit-count ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "4" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "-1 32 bits bit-count ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								               "32" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								               "B{ 1 0 1 } bit-count ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "2" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  bitroll-32  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "m"  integer  } { "s"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Rolls the number "  { $snippet "m"  } " by "  { $snippet "s"  } " bits to the left, wrapping around after 32 bits."  }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0x1 10 bitroll-32 .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "400" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0x1 -10 bitroll-32 .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "400000" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  bitroll-64  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "m"  integer  } { "s"  "a shift integer"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Rolls the number "  { $snippet "m"  } " by "  { $snippet "s"  } " bits to the left, wrapping around after 64 bits."  }
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0x1 10 bitroll-64 .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "400" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "0x1 -10 bitroll-64 .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               "40000000000000" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ bitroll bitroll-32 bitroll-64 } related-words
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  clear-bit  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the nth bit of "  { $snippet "x"  } " to zero."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 7 clear-bit .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "7f" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-06-18 12:41:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  symbols>flags  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values { "symbols"  sequence  } { "assoc"  assoc  } { "flag-bits"  integer  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Constructs an integer value by mapping the values in the "  { $snippet "symbols"  } " sequence to integer values using "  { $snippet "assoc"  } " and "  { $link bitor  } "ing the values together."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ui.gadgets.worlds ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "IN: scratchpad" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "CONSTANT: window-controls>flags H{" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { close-button 1 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { minimize-button 2 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { maximize-button 4 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { resize-handles 8 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { small-title-bar 16 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "    { normal-title-bar 32 }" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "}" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "{ resize-handles close-button small-title-bar } window-controls>flags symbols>flags ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "25" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  >even  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "m"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "7 >even ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "6" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the lowest bit in the integer to 0, which either does nothing or outputs 1 less than the input integer."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  >odd  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "m"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "4 >odd ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "5" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the lowest bit in the integer to 1, which either does nothing or outputs 1 more than the input integer."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  >signed  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 8 >signed ." 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "-1" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Interprets a number "  { $snippet "x"  } " as an "  { $snippet "n"  } "-bit number and converts it to a negative number "  { $snippet "n"  } "-bit number if the topmost bit is set."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  mask  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "?"  "a boolean"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "After the operation, only the bits that were set in both the mask and the original number are set."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0b11111111 0b101 mask .b" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "101" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  mask-bit  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m'"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Turns off all bits besides the nth bit."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 2 mask-bit .b" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "100" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  mask?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "?"  "a boolean"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns true if all of the bits in the mask "  { $snippet "n"  } " are set in the integer input "  { $snippet "x"  } "."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 0xf mask? ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "t" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xf0 0x1 mask? ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "f" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  even-parity?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "obj"  object  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "?"  boolean  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns true if the number of set bits in an object is even."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  odd-parity?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "obj"  object  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "?"  boolean  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns true if the number of set bits in an object is odd."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  on-bits  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Returns an integer with "  { $snippet "m"  } " bits set."  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "6 on-bits .h" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "3f" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "64 on-bits .h" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "ffffffffffffffff" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-29 01:37:36 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  toggle-bit  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m'"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-29 01:37:36 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Toggles the nth bit of an integer."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "0 3 toggle-bit .b" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "1000" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0b1000 3 toggle-bit .b" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-29 01:37:36 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  set-bit  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the nth bit of "  { $snippet "x"  } "."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "0 5 set-bit .h" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "20" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  shift-mod  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "m"  integer  } { "s"  integer  } { "w"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-01-30 16:21:46 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Calls "  { $link shift  } " on "  { $snippet "n"  } " and "  { $snippet "s"  } ", wrapping the result to "  { $snippet "w"  } " bits."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  unmask  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "?"  "a boolean"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Clears the bits in "  { $snippet "x"  } " if they are set in the mask "  { $snippet "n"  } "."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 0x0f unmask .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "f0" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  unmask?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "?"  "a boolean"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Tests whether unmasking the bits in "  { $snippet "x"  } " would return an integer greater than zero."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xff 0x0f unmask? ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "t" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  w*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Multiplies two integers and wraps the result to a 32-bit unsigned integer."  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xffffffff 0x2 w* ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "4294967294" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  w+  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Adds two integers and wraps the result to a 32-bit unsigned integer."  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xffffffff 0x2 w+ ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "1" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  w-  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-02-18 18:31:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Subtracts two integers and wraps the result to a 32-bit unsigned integer."  }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0x0 0xff w- ." 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "4294967041" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  W*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Multiplies two integers and wraps the result to a 64-bit unsigned integer."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xffffffffffffffff 0x2 W* ." 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "18446744073709551614" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  W+  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Adds two integers and wraps the result to 64-bit unsigned integer."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xffffffffffffffff 0x2 W+ ." 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "1" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  W-  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "x"  integer  } { "y"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "z"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Subtracts two integers and wraps the result to a 64-bit unsigned integer."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { $example "USING: math.bitwise kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0x0 0xff W- ." 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "18446744073709551361" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  wrap  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m"  integer  } { "n"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     { "m'"  integer  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Wraps an integer "  { $snippet "m"  } " by modding it by "  { $snippet "n"  } ". This word is uses bitwise arithmetic and does not actually call the modulus word, and as such can only mod by powers of two."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples "Equivalent to modding by 8:" 
							 
						 
					
						
							
								
									
										
										
										
											2011-01-16 10:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { $example
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "USING: math.bitwise prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-23 21:49:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "0xffff 8 wrap .h" 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        "7" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ARTICLE: "math-bitfields"  "Constructing bit fields" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Some applications, such as binary communication protocols and assemblers, need to construct integers from elaborate bit field specifications. Hand-coding this using "  { $link shift  } " and "  { $link bitor  } " results in repetitive code. A higher-level facility exists to factor out this repetition:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections bitfield } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 20:23:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ARTICLE: "math.bitwise"  "Additional bitwise arithmetic" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"The "  { $vocab-link "math.bitwise"  } " vocabulary provides bitwise arithmetic words extending "  { $link "bitwise-arithmetic"  } ". They are useful for efficiency, low-level programming, and interfacing with C libraries."  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$nl
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Setting and clearing bits:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    set-bit
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    clear-bit
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Testing if bits are set or clear:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bit?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bit-clear?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2012-09-19 17:54:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Extracting bits from an integer:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bit-range
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bits
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-03-24 04:04:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Toggling a bit:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    toggle-bit
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Operations with bitmasks:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    mask
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unmask
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    mask?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unmask?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Generating an integer with n set bits:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections on-bits }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Counting the number of set bits:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections bit-count }
							 
						 
					
						
							
								
									
										
										
										
											2009-10-05 19:55:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Testing the parity of an object:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections even-parity? odd-parity? }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"More efficient modding by powers of two:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections wrap }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Bit-rolling:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bitroll
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bitroll-32
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bitroll-64
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"32-bit arithmetic:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    w+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    w-
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    w*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2011-09-21 15:55:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"64-bit arithmetic:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    W+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    W-
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    W*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Converting a number to the nearest even/odd:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    >even
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    >odd
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Bitfields:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "math-bitfields" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-11 14:03:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ABOUT: "math.bitwise"