Geohash::binEncode PHP Method

binEncode() private method

create binary encoding of number as detailed in http://en.wikipedia.org/wiki/Geohash#Example removing the tail recursion is left an exercise for the reader
private binEncode ( $number, $min, $max, $bitcount )
    private function binEncode($number, $min, $max, $bitcount)
    {
        if ($bitcount == 0) {
            return "";
        }
        #echo "$bitcount: $min $max<br>";
        //this is our mid point - we will produce a bit to say
        //whether $number is above or below this mid point
        $mid = ($min + $max) / 2;
        if ($number > $mid) {
            return "1" . $this->binEncode($number, $mid, $max, $bitcount - 1);
        } else {
            return "0" . $this->binEncode($number, $min, $mid, $bitcount - 1);
        }
    }