Skip to content

Instantly share code, notes, and snippets.

@mikeshiyan
Created December 18, 2015 08:36
Show Gist options
  • Save mikeshiyan/e2c2e682c47962bf8af5 to your computer and use it in GitHub Desktop.
Save mikeshiyan/e2c2e682c47962bf8af5 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Analogue of JS Unsigned Right Shift Operator (>>>).
*/
/**
* Shifts $int in binary representation $steps (< 32) bits to the right,
* discarding bits shifted off, and shifting in zeros from the left.
*
* @param int $int
* @param int $steps
*
* @return int
*/
function unsigned_right_shift($int, $steps) {
return ($int >> $steps) & (pow(2, 32 - $steps) - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment