lgscript:bit_library

Functions that manipulate numbers as 32-bit integers. Input numbers can be as low as -2^{31} and as high as 2^{32}-1. (Some of those numbers will have the same binary representation.) The processing is done using unsigned 32-bit numbers, so the return values are always greater than or equal to 0.

Arithmetic right shift.

Returns | number | The shifted value. |
---|---|---|

Parameter | number | A bitfield value. |

Parameter | number | Number of places to shift. |

Shift the bits in the number to the right. The bits shifted in from the left will be the same as the previous high-order bit. A negative shift will go to the left and set the low-order bits to 0.

Bitwise and of the given numbers.

Returns | number | The and’ed value. |
---|---|---|

Parameter | number `...` | Values to and together. |

Bitwise not of the number.

Returns | number | The inverted value. |
---|---|---|

Parameter | number | Value to invert. |

Bitwise or of the given numbers.

Returns | number | The or’ed value. |
---|---|---|

Parameter | number `...` | Values to or together. |

Do bitwise and and test the result.

Returns | boolean | True if the result is not zero. |
---|---|---|

Parameter | number `...` | Values to and together. |

Bitwise xor of the given numbers.

Returns | number | The xored value. |
---|---|---|

Parameter | number `...` | Values to xor together. |

Left rotate.

Returns | number | The shifted value. |
---|---|---|

Parameter | number | A bitfield value. |

Parameter | number | Number of places to shift. |

Shift the bits in the number to the left. A negative shift will go to the right. Each bit removed from the left side will be inserted on the right side. So the number will restore itself if shifted 32 places.

Left shift.

Returns | number | The shifted value. |
---|---|---|

Parameter | number | A bitfield value. |

Parameter | number | Number of places to shift. |

Shift the bits in the number to the left. A negative shift will go to the right. The shifted in bits are set to 0.

Right rotate.

Returns | number | The shifted value. |
---|---|---|

Parameter | number | A bitfield value. |

Parameter | number | Number of places to shift. |

Shift the bits in the number to the right. A negative shift will go to the left. Each bit removed from the right side will be inserted on the left side. So the number will restore itself if shifted 32 places.

Right shift.

Returns | number | The shifted value. |
---|---|---|

Parameter | number | A bitfield value. |

Parameter | number | Number of places to shift. |

Shift the bits in the number to the right. A negative shift will go to the left. The shifted in bits are set to 0.

- Next: io_library →

lgscript/bit_library.txt · Last modified: 2011/05/21 01:54 by telliamed