HOTP.php
protected function counterToString($counter)
    {
        $tmp = "";
        while ($counter != 0) {
            $tmp .= chr($counter & 0xff);
            $counter >>= 8;
        }

        return substr(str_pad(strrev($tmp), 8, "\0", STR_PAD_LEFT), 0, 8);
    }
protected function counterToString($counter)
    {
        $tmp = "";
        while ($counter != 0) {
            $tmp .= chr($counter & 0xff);
            $counter >>= 8;
        }

        return substr(str_pad(strrev($tmp), 8, "\0", STR_PAD_LEFT), 0, 8);
    }
Convert an integer counter into a string of 8 bytes.

@param  integer $counter The counter value
@return string Returns an 8-byte binary string