当前位置: 首页>>代码示例>>PHP>>正文


PHP bindec函数代码示例

本文整理汇总了PHP中bindec函数的典型用法代码示例。如果您正苦于以下问题:PHP bindec函数的具体用法?PHP bindec怎么用?PHP bindec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bindec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getIp

 /**
  * 返回客户端的IP地址
  * @param boolean $is_int 所否返回整形IP地址
  * @return int/string $ip 用户IP地址 
  */
 public static function getIp($is_int = false)
 {
     //$ip = false;
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER["REMOTE_ADDR"];
     } else {
         if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
             $ip = $_SERVER["HTTP_CLIENT_IP"];
         }
     }
     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
         if ($ip) {
             array_unshift($ips, $ip);
             $ip = FALSE;
         }
         for ($i = 0; $i < count($ips); $i++) {
             if (!preg_match("/^(0|10|127|172\\.16|192\\.168)\\./", $ips[$i])) {
                 $ip = $ips[$i];
                 break;
             }
         }
     }
     $ip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
     $ip = $ip ? $ip : '0.0.0.0';
     return $is_int ? bindec(decbin(ip2long($ip))) : $ip;
 }
开发者ID:nbaiwan,项目名称:yav,代码行数:32,代码来源:Common.php

示例2: mv_decrypt

function mv_decrypt($str_hex, $key1, $key2)
{
    $str_bin = "";
    // 1. Convert hexadecimal string to binary string
    for ($i = 0; $i < 128; $i++) {
        $str_bin .= floor(hexdec($str_hex[floor($i / 4)]) / pow(2, 3 - $i % 4)) % 2;
    }
    // 2. Generate switch and XOR keys
    $key = array();
    for ($i = 0; $i < 384; $i++) {
        $key1 = ($key1 * 11 + 77213) % 81371;
        $key2 = ($key2 * 17 + 92717) % 192811;
        $key[$i] = ($key1 + $key2) % 128;
    }
    // 3. Switch bits positions
    for ($i = 256; $i >= 0; $i--) {
        $temp = $str_bin[$key[$i]];
        $str_bin[$key[$i]] = $str_bin[$i % 128];
        $str_bin[$i % 128] = $temp;
    }
    // 4. XOR entire binary string
    for ($i = 0; $i < 128; $i++) {
        $str_bin[$i] = $str_bin[$i] ^ $key[$i + 256] & 1;
    }
    // 5. Convert binary string back to hexadecimal
    $str_hex = "";
    for ($i = 0; $i < 32; $i++) {
        $str_hex .= dechex(bindec(substr($str_bin, $i * 4, 4)));
    }
    // 6. Return counted string
    return $str_hex;
}
开发者ID:johnymarek,项目名称:eboda-hd-for-all-500,代码行数:32,代码来源:megavideo.php

示例3: parse

 /**
  * Parses a DNUMBER token like PHP would.
  *
  * @param string $str A string number
  *
  * @return float The parsed number
  */
 public static function parse($str)
 {
     // if string contains any of .eE just cast it to float
     if (false !== strpbrk($str, '.eE')) {
         return (double) $str;
     }
     // otherwise it's an integer notation that overflowed into a float
     // if it starts with 0 it's one of the special integer notations
     if ('0' === $str[0]) {
         // hex
         if ('x' === $str[1] || 'X' === $str[1]) {
             return hexdec($str);
         }
         // bin
         if ('b' === $str[1] || 'B' === $str[1]) {
             return bindec($str);
         }
         // oct
         // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
         // so that only the digits before that are used
         return octdec(substr($str, 0, strcspn($str, '89')));
     }
     // dec
     return (double) $str;
 }
开发者ID:ck-1,项目名称:PHP-Parser,代码行数:32,代码来源:DNumber.php

示例4: getInt

 /**
  * 获取整形ip
  */
 static function getInt($ip)
 {
     if (self::checkIP($ip)) {
         return bindec(decbin(ip2long($ip)));
     }
     return 0;
 }
开发者ID:beelibrary820145,项目名称:tanxiongfeng,代码行数:10,代码来源:Ip.class.php

示例5: jugglingzero

function jugglingzero($data)
{
    // inialise the variables
    $strBinary = "";
    $arZeros = array();
    $arSeries = array();
    //explode the zeros;
    $arZeros = explode(" ", $data);
    //separate the zero flags to the series
    for ($i = 0; $i < count($arZeros); $i++) {
        if ($i % 2 == 0) {
            $arFlags[] = $arZeros[$i];
        } else {
            $arSeries[] = $arZeros[$i];
        }
    }
    // lets iterate through each flags
    for ($i = 0; $i < count($arFlags); $i++) {
        // if flag is equal to string zero
        if ($arFlags[$i] === "0") {
            // concatenate the series
            $strBinary .= $arSeries[$i];
        } else {
            // replace the zero to one in the series
            // before concatenation
            $strBinary .= str_replace("0", "1", $arSeries[$i]);
        }
    }
    // then convert the binary to integer
    echo bindec($strBinary);
}
开发者ID:kcabading,项目名称:CodeEvalChallenges,代码行数:31,代码来源:jugglingwithzero.php

示例6: __set

 /**
  * This method sets the value for the specified field.
  *
  * @access public
  * @param string $field                                     the name of the field
  * @param mixed $value                                      the value of the field
  * @throws Throwable\InvalidProperty\Exception              indicates that the specified property is
  *                                                          either inaccessible or undefined
  */
 public function __set($field, $value)
 {
     if (!array_key_exists($field, $this->values)) {
         throw new Throwable\InvalidProperty\Exception('Unable to set the specified property. Property :field is either inaccessible or undefined.', array(':field' => $field, ':value' => $value));
     }
     $this->values[$field] = bindec(static::unpack($value, $this->boundary));
 }
开发者ID:bluesnowman,项目名称:Chimera,代码行数:16,代码来源:BitField.php

示例7: to64Bit

 /**
  * Convert 32-bit SteamID to 64-bit SteamID
  *
  * @param string|int $userId
  *
  * @return string
  * @throws Exception
  */
 public static function to64Bit($userId)
 {
     if (!function_exists('gmp_add')) {
         throw new Exception("GMP Library not installed. Cannot convert SteamIDs.");
     }
     return gmp_strval(gmp_add(gmp_mul(sprintf("%u", bindec(self::STEAM_ID_UPPER_BITS)), "4294967296"), sprintf("%u", $userId)));
 }
开发者ID:sjaakmoes,项目名称:dotapi2,代码行数:15,代码来源:UserId.php

示例8: timeFromParticle

 public static function timeFromParticle($particle)
 {
     /*
      * Return time
      */
     return bindec(substr(decbin($particle), 0, 41)) - pow(2, 40) + 1 + self::EPOCH;
 }
开发者ID:wwek,项目名称:Particle.php,代码行数:7,代码来源:Particle.php

示例9: match_ip

/**
 * Checks a IPv4 address against a whitelist
 *
 * @param $ip IPv4 address in GeoIP or human readable format
 * @param $matches array of IPv4 addresses
 * @return true if $ip address is found in the $matches list
 */
function match_ip($ip, $matches)
{
    if (!is_numeric($ip)) {
        $ip = IPv4_to_GeoIP($ip);
    }
    foreach ($matches as $chk) {
        $a = explode('/', $chk);
        //check against "80.0.0.0/8" format
        if (count($a) == 2) {
            $lo = IPv4_to_GeoIP($a[0]);
            if ($ip >= $lo) {
                $hi = $lo + bindec('1' . str_repeat('0', 32 - $a[1])) - 1;
                //echo "lo: ".GeoIP_to_IPv4($lo)."   (".$lo.")\n";
                //echo "hi: ".GeoIP_to_IPv4($hi)."   (".$hi.")\n";
                if ($ip <= $hi) {
                    return true;
                }
            }
        } else {
            if ($ip == IPv4_to_GeoIP($chk)) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:martinlindhe,项目名称:core_dev,代码行数:33,代码来源:network.php

示例10: run

 public function run(&$arrData, $arrConf)
 {
     if (empty($arrData) || !is_array($arrData)) {
         return false;
     }
     $arrBitZoneConf = Util::getConf('/bitzone', 'BITZONE');
     $arrBitZoneConf = $this->analysisConf($arrBitZoneConf);
     if (empty($arrBitZoneConf)) {
         return false;
     }
     // 遍历获得asResult->item->0/1/..->urls->asurls->strategys中的标志位数组
     // 取得配置中各标志位在上述数组位置中的值
     // 将最终解析出来的标志位值加入asResult->item->0/1/..->dispData->strategybits中
     if (!empty($arrData['uiData']['asResult']['item']) && is_array($arrData['uiData']['asResult']['item'])) {
         foreach ($arrData['uiData']['asResult']['item'] as &$asResultItem) {
             $arrBitZoneInfo = array();
             if (!empty($asResultItem['urls']['asUrls']['strategys']) && is_array($asResultItem['urls']['asUrls']['strategys'])) {
                 foreach ($arrBitZoneConf as $strTipKey => $arrTipConfInfo) {
                     $strTipValue = '';
                     foreach ($arrTipConfInfo as $intSection => $arrPos) {
                         $intStrategySectionNum = intval($asResultItem['urls']['asUrls']['strategys'][$intSection]);
                         foreach ($arrPos as $intPos) {
                             $intTmp = ($intStrategySectionNum & pow(2, $intPos)) == 0 ? 0 : 1;
                             $strTipValue = $strTipValue === '' ? $intTmp : $strTipValue . $intTmp;
                         }
                     }
                     $arrBitZoneInfo[$strTipKey] = bindec($strTipValue);
                 }
             }
             $asResultItem['dispData']['strategybits'] = $arrBitZoneInfo;
         }
     }
     return true;
 }
开发者ID:drehere,项目名称:shenmegui,代码行数:34,代码来源:BitZone.php

示例11: make_cache

function make_cache($type, $from, $to, $cache_time, $rewrite = false)
{
    $hour_key = date('H', $from);
    // Кэш дневной ленты переходов
    $params = array('type' => 'basic', 'part' => 'hour', 'filter' => array(), 'group_by' => $type, 'subgroup_by' => $type, 'conv' => 'all', 'mode' => '', 'col' => 'sale_lead', 'from' => date('Y-m-d H:i:s', $from), 'to' => date('Y-m-d H:i:s', $to), 'cache' => 2);
    $arr_report_data = get_clicks_report_grouped2($params);
    /*
    		dmp($params);
    		dmp($arr_report_data);
    		die();*/
    $str = join('', $arr_report_data['click_params']) . join('', $arr_report_data['campaign_params']);
    echo $str . '<br />';
    if (empty($arr_report_data['data'])) {
        return false;
    }
    foreach ($arr_report_data['data'] as $k => $v) {
        $r = $v[$hour_key];
        $ins = array('type' => $type, 'id' => $r['id'], 'time' => $cache_time, 'name' => $r['name'], 'price' => $r['price'], 'unique' => $r['unique'], 'income' => $r['income'], 'direct' => $r['direct'], 'sale' => $r['sale'], 'lead' => $r['lead'], 'act' => $r['act'], 'out' => $r['out'], 'cnt' => $r['cnt'], 'sale_lead' => $r['sale_lead'], 'rebuild' => 0, 'params' => bindec($str));
        $q = insertsql($ins, 'tbl_clicks_cache_hour', true);
        echo $q . '<br />';
        db_query($q);
    }
    if ($rewrite) {
        $q = "update `tbl_clicks_cache_hour` set `rebuild` = '0' where `time` = '" . $cache_time . "'";
        db_query($q);
    }
    return true;
}
开发者ID:conversionstudio,项目名称:cpatracker,代码行数:28,代码来源:process_cache.php

示例12: createCode

 public function createCode()
 {
     for ($i = 0; $i < 4; $i++) {
         $this->text .= rand(0, 1);
     }
     $this->checkcode = bindec(intval($this->text));
 }
开发者ID:justfu,项目名称:lavender,代码行数:7,代码来源:CheckCode.class.php

示例13: base32decode

/**
 * Decodes base32
 *
 * @param string $base32String Base32 encoded string
 * @return string Clear text string
 */
function base32decode($base32String)
{
    $base32alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=';
    // Only work in upper cases
    $base32String = strtoupper($base32String);
    // Remove anything that is not base32 alphabet
    $pattern = '/[^A-Z2-7]/';
    $base32String = preg_replace($pattern, '', $base32String);
    if (strlen($base32String) == 0) {
        // Gives an empty string
        return '';
    }
    $base32Array = str_split($base32String);
    $string = '';
    foreach ($base32Array as $str) {
        $char = strpos($base32alphabet, $str);
        // Ignore the padding character
        if ($char !== 32) {
            $string .= sprintf('%05b', $char);
        }
    }
    while (strlen($string) % 8 !== 0) {
        $string = substr($string, 0, strlen($string) - 1);
    }
    $binaryArray = base32chunk($string, 8);
    $realString = '';
    foreach ($binaryArray as $bin) {
        // Pad each value to 8 bits
        $bin = str_pad($bin, 8, 0, STR_PAD_RIGHT);
        // Convert binary strings to ASCII
        $realString .= chr(bindec($bin));
    }
    return $realString;
}
开发者ID:w1lliams,项目名称:sh,代码行数:40,代码来源:helpers.php

示例14: getUniqueID2

 public static function getUniqueID2()
 {
     // The field names refer to RFC 4122 section 4.1.2
     $uuid = sprintf('%04x%04x-%04x-%03x4-%04x-%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 4095), bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
     $uuid = 'id' . str_replace('-', '', $uuid);
     return $uuid;
 }
开发者ID:r007,项目名称:PMoodle,代码行数:7,代码来源:uuid.class.php

示例15: update_field

 function update_field($field)
 {
     if (!$this->id) {
         return ERR_NO_ORDER_CHOSEN;
     }
     if (!isset($this->allow_single_update)) {
         return ERR_NOT_ALLOWED_TO_CHANGE_FIELD;
     }
     if (!in_array($field, $this->allow_single_update)) {
         return ERR_NOT_ALLOWED_TO_CHANGE_FIELD;
     }
     $this->fetch_data();
     $input_data = $this->data;
     $new_value = $this->data[$field] ? 0 : 1;
     if ($field == 'level') {
         $this->get_level();
         $lev = $this->level;
         $idx = $_REQUEST['data']['subfield'];
         $lev[$idx] = $lev[$idx] ? 0 : 1;
         krsort($lev);
         foreach ($lev as $val) {
             $levinv .= $val;
         }
         $levinv = bindec($levinv);
         $new_value = $levinv;
     }
     if ($err = $this->set($field, $new_value)) {
         return $err;
     }
     return 0;
 }
开发者ID:jaimeivan,项目名称:smart-restaurant,代码行数:31,代码来源:user_class.php


注:本文中的bindec函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。