• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP bindec函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getRank

 /**
  * getRank
  *
  * @access public
  * @param numeric $rgb2 rgb1
  * @param numeric $rgb2 rgb2
  * @param numeric $rgb3 rgb3
  * @return int
  */
 public function getRank($rgb1, $rgb2, $rgb3)
 {
     $a = $this->dec2bin($rgb1);
     $b = $this->dec2bin($rgb2);
     $c = $this->dec2bin($rgb3);
     return bindec($a[0] . $a[5] . $b[0] . $b[5] . $c[0] . $c[5]);
 }
开发者ID:Terrah4wk,项目名称:recruitmentTest2012,代码行数:16,代码来源:dataHandler.php


示例17: setFolderPermissions

 public static function setFolderPermissions($dir, $io)
 {
     $changePerms = function ($path, $perms, $io) {
         $currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4));
         if (($currentPerms & $perms) == $perms) {
             return;
         }
         $res = chmod($path, $currentPerms | $perms);
         if ($res) {
             $io->write('Permissions set on ' . $path);
         } else {
             $io->write('Failed to set permissions on ' . $path);
         }
     };
     $walker = function ($dir, $perms, $io) use(&$walker, $changePerms) {
         $files = array_diff(scandir($dir), ['.', '..']);
         foreach ($files as $file) {
             $path = $dir . '/' . $file;
             if (!is_dir($path)) {
                 continue;
             }
             $changePerms($path, $perms, $io);
             $walker($path, $perms, $io);
         }
     };
     $worldWritable = bindec('0000000111');
     $walker($dir . '/Tmp', $worldWritable, $io);
     $changePerms($dir . '/Tmp', $worldWritable, $io);
     $changePerms($dir . '/Tmp/Log', $worldWritable, $io);
 }
开发者ID:NuBOXDevCom,项目名称:nmvc-app,代码行数:30,代码来源:Installer.php


示例18: fromString

 /**
  * Try get the range instance starting from its string representation.
  *
  * @param string|mixed $range
  *
  * @return static|null
  */
 public static function fromString($range)
 {
     $result = null;
     if (is_string($range)) {
         $parts = explode('/', $range);
         if (count($parts) === 2) {
             $address = Factory::addressFromString($parts[0]);
             if ($address !== null) {
                 if (preg_match('/^[0-9]{1,9}$/', $parts[1])) {
                     $networkPrefix = @intval($parts[1]);
                     if ($networkPrefix >= 0) {
                         $addressBytes = $address->getBytes();
                         $totalBytes = count($addressBytes);
                         $numDifferentBits = $totalBytes * 8 - $networkPrefix;
                         if ($numDifferentBits >= 0) {
                             $numSameBytes = $networkPrefix >> 3;
                             $sameBytes = array_slice($addressBytes, 0, $numSameBytes);
                             $differentBytesStart = $totalBytes === $numSameBytes ? array() : array_fill(0, $totalBytes - $numSameBytes, 0);
                             $differentBytesEnd = $totalBytes === $numSameBytes ? array() : array_fill(0, $totalBytes - $numSameBytes, 255);
                             $startSameBits = $networkPrefix % 8;
                             if ($startSameBits !== 0) {
                                 $varyingByte = $addressBytes[$numSameBytes];
                                 $differentBytesStart[0] = $varyingByte & bindec(str_pad(str_repeat('1', $startSameBits), 8, '0', STR_PAD_RIGHT));
                                 $differentBytesEnd[0] = $differentBytesStart[0] + bindec(str_repeat('1', 8 - $startSameBits));
                             }
                             $result = new static(Factory::addressFromBytes(array_merge($sameBytes, $differentBytesStart)), Factory::addressFromBytes(array_merge($sameBytes, $differentBytesEnd)), $networkPrefix);
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }
开发者ID:mlocati,项目名称:ip-lib,代码行数:41,代码来源:Subnet.php


示例19: calcRange

 static function calcRange($iparray)
 {
     //print_r($iparray);
     $iparray = array_unique($iparray);
     $iparray = array_map("ip2long", $iparray[0]);
     sort($iparray);
     $iparray = array_map("long2ip", $iparray);
     $ip_begin = $iparray[0];
     $ip_end = $iparray[count($iparray) - 1];
     $ip_begin_bin = self::ip2bin($ip_begin);
     $ip_end_bin = self::ip2bin($ip_end);
     $ip_shortened = self::findMatch(implode('', $ip_begin_bin), implode('', $ip_end_bin));
     $cidr_range = strlen($ip_shortened);
     $cidr_difference = 32 - $cidr_range;
     $cidr_begin = $ip_shortened . str_repeat('0', $cidr_difference);
     $cidr_end = $ip_shortened . str_repeat('1', $cidr_difference);
     $ip_count = bindec($cidr_end) - bindec($cidr_begin) + 1;
     $ips = array();
     foreach ($iparray as $ip) {
         $ips[] = array('ip' => $ip, 'bin' => implode('.', self::ip2bin($ip)), 'rdns' => gethostbyaddr($ip), 'long' => ip2long($ip), 'hex' => implode('.', self::ip2hex($ip)), 'octal' => implode('.', self::ip2oct($ip)), 'radians' => implode('/', self::ip2rad($ip)), 'base64' => implode('.', self::ip264($ip)), 'alpha' => implode('.', self::ip2alpha($ip)));
     }
     usort($ips, array('IPCalc', 'ipsort'));
     $tmp = self::calcCIDR($ip_begin . '/' . $cidr_range);
     return array('begin' => $tmp['begin'], 'end' => $tmp['end'], 'count' => $tmp['count'], 'suffix' => $cidr_range, 'ips' => $ips);
 }
开发者ID:JackPotte,项目名称:xtools,代码行数:25,代码来源:base.php


示例20: strdecodebase32

 public function strdecodebase32($str)
 {
     if (strlen($str) % 8 > 0) {
         throw new Exception("Str length must be a multiple of 8");
     }
     if (empty($str)) {
         return "";
     }
     $len = strpos($str, "=");
     if ($len !== FALSE) {
         $str = substr($str, 0, $len);
     }
     $quanta = str_split($str, 8);
     $decoded = "";
     foreach ($quanta as $quantum) {
         $_8bitchars = "";
         for ($i = 0; $i < strlen($quantum); $i++) {
             $code = strpos($this->charset, $quantum[$i]);
             if ($code === FALSE) {
                 throw new Exception("Invalid charset.");
             }
             $_8bitchars .= str_pad(decbin($code), 5, "0", STR_PAD_LEFT);
         }
         foreach (str_split($_8bitchars, 8) as $char) {
             $decoded .= chr(bindec($char));
         }
     }
     return $decoded;
 }
开发者ID:butshuti,项目名称:phptotp,代码行数:29,代码来源:totp.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP bindtextdomain函数代码示例发布时间:2022-05-24
下一篇:
PHP bind_textdomain_codeset函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap