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


PHP decbin函数代码示例

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


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

示例1: getParidad

 public function getParidad($mensaje)
 {
     $numero_max = strlen($g) - 1;
     $num = strlen($mensaje);
     $array_mensaje = array();
     for ($a = 0; $a < $num; $a++) {
         $array_mensaje[] = 0 . decbin(ord($mensaje[$a]));
         $mensaje_bin .= decbin(ord($mensaje[$a]));
         $suma_ascii += ord($mensaje[$a]);
         $array_final['suma_bin'] .= 0;
         //echo $mensaje[$a]." - ".decbin(ord($mensaje[$a]))." <br>";
     }
     $suma_bin = decbin($suma_ascii);
     $conteo_hor = 0;
     for ($j = 0; $j < $num; $j++) {
         $valor_par = 0;
         for ($i = 0; $i < 7; $i++) {
             $array_final[$j][$i] = $array_mensaje[$j][$i];
             $valor_par = $array_mensaje[$j][$i] == 1 ? $valor_par + 1 : $valor_par + 0;
         }
         $array_final[$j]['paridad'] = $this->validaParidad($valor_par, $mensaje);
         $conteo_hor += $array_final[$j]['paridad'];
     }
     $array_final['conteo_hor'] = $conteo_hor;
     $array_final['mensaje_bin'] = $mensaje_bin;
     $array_final['suma_bin'] .= $suma_bin;
     return $array_final;
 }
开发者ID:nmcantorp,项目名称:convertir,代码行数:28,代码来源:crc.php

示例2: GetTypesByDecimal

function GetTypesByDecimal($decimal = 0)
{
    /**
    			 Bit 	=	Type Name					= 	Value store in DB
    			 ------------------------------------------------------------
    			 1		=	Manual Action				=	0
    			 2		=	Offer(automatic)			=	1
    			 4		=	Coupon (automatic)			=	2
    			 8		=	New Affiliates (automatic)	=	3
    			 16		=	New Invoices (automatic)	=	4
    			 32		= 	Products Feed (automatic)	=	5
    			 **/
    $bit_vs_types = array(1 => 0, 2 => 1, 4 => 2, 8 => 3, 16 => 4, 32 => 5);
    if (!$decimal || $decimal < 0) {
        return $decimal;
    }
    echo $decimal . ' = ' . ($decToBin = decbin($decimal));
    echo "<br>";
    $length = $count = strlen($decToBin);
    for ($i = 0; $i < $length; $i++) {
        echo $number = $decToBin[$i] * pow(2, --$count);
        echo "<br>";
        if ($number) {
            $ids[$i] = $bit_vs_types[$number];
        }
    }
    sort($ids);
    return $ids;
}
开发者ID:mackraja,项目名称:practise,代码行数:29,代码来源:test3.php

示例3: main

function main($num)
{
    if ($num < 0) {
        $s = 1;
        $num = -$num;
    } else {
        $s = 0;
    }
    $zs = floor($num);
    $bzs = decbin($zs);
    $xs = $num - $zs;
    $res = (double) ($bzs . '.' . tenToBinary($xs, 1));
    $teme = ws($res);
    $e = decbin($teme + 127);
    if ($teme == 0) {
        $e = '0' . $e;
    }
    $temm = $res / pow(10, $teme);
    $m = end(explode(".", $temm));
    $lenm = strlen($m);
    if ($lenm < 23) {
        $m .= addzero(23 - $lenm);
    }
    return $s . ' ' . $e . ' ' . $m . ' ';
}
开发者ID:echosoar,项目名称:phpBinary,代码行数:25,代码来源:floatToIEEE32.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: index

 function index()
 {
     $dota = Dota::me();
     if (isset($this->args[0])) {
         $match_id = (int) $this->args[0];
     }
     if (!empty($match_id)) {
         $steam_ids_array = array();
         $match = $dota->get_match_by_id($match_id);
         foreach ($match['players'] as $key => $player) {
             if ($player['account_id'] == 4294967295.0) {
                 continue;
             }
             $steam_ids_array[$key] = $player['account_id'];
         }
         $profiles = $dota->get_user_profiles($steam_ids_array);
         foreach ($profiles as $key => $profile) {
             $match['players'][$key]['profile'] = $profile;
         }
         $match['tower_radiant'] = decbin(32768 + $match['tower_status_radiant']);
         $match['tower_dire'] = decbin(32768 + $match['tower_status_dire']);
         $match['barak_radiant'] = decbin(128 + $match['barracks_status_radiant']);
         $match['barak_dire'] = decbin(128 + $match['barracks_status_dire']);
         $this->des->set('spells', $dota->get_spells());
         //$this->des->set('arr', $arr['result']);
         $this->des->set('match', $match);
     }
     $this->des->set('dota', $dota);
     $this->des->display('match');
 }
开发者ID:kostarev,项目名称:test,代码行数:30,代码来源:match.php

示例6: testTransforms

 public function testTransforms()
 {
     $t = new IntMethods();
     $this->assertEquals(decbin(255), $t->getBinary(255));
     $this->assertEquals(dechex(255), $t->getHex(255));
     $this->assertEquals(decoct(255), $t->getOctal(255));
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:7,代码来源:IntMethodTest.php

示例7: poll_ipAddress

 /**
  * poller ipAddress
  *
  * @return Array
  */
 public function poll_ipAddress()
 {
     // return
     $_ret = [];
     $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro);
     // walk OID_ipAdEntIfIndex
     $walk_ipAdEntIfIndex = $snmp->walk(OID_ipAdEntIfIndex);
     if (count($walk_ipAdEntIfIndex) == 0 || $walk_ipAdEntIfIndex === false) {
         // not found ipAddress
         return $_ret;
     }
     // walk netmask
     $walk_ipAdEntNetMask = $snmp->walk(OID_ipAdEntNetMask);
     // oid.ipAddress(4) = ifIndex
     foreach ($walk_ipAdEntIfIndex as $key1 => $ifIndex) {
         $ipAddress = str_replace(OID_ipAdEntIfIndex . '.', '', $key1);
         $netmask = explode('.', $walk_ipAdEntNetMask[OID_ipAdEntNetMask . '.' . $ipAddress]);
         if (count($netmask) == 4) {
             $masks = substr_count(decbin($netmask[0]), 1) + substr_count(decbin($netmask[1]), 1) + substr_count(decbin($netmask[2]), 1) + substr_count(decbin($netmask[3]), 1);
         } else {
             $masks = 0;
         }
         $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first();
         if ($port) {
             // found port and vlan
             $_ret[] = ['table' => 'ips', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id], 'data' => ['ipAddress' => $ipAddress, 'masks' => $masks]];
         }
     }
     return $_ret;
 }
开发者ID:afdalwahyu,项目名称:lnms,代码行数:35,代码来源:Ip.php

示例8: decryption_str

/**
 * 这个程序是针对加密的字符串进行解密
 * @param $str 需要解密的字符串
 * @param $restr 解密完成的代码
 */
function decryption_str($str)
{
    $len = strlen($str);
    $len_b = decbin($len);
    $arr = str_split($str);
    for ($i = 0; $i < $len; $i++) {
        $dec[$i] = ord($arr[$i]);
        $hex[$i] = str_pad(dechex($dec[$i]), 2, 0, STR_PAD_LEFT);
    }
    $str_hex = implode($hex);
    //***2***
    $str_hex = str_ireplace('FF', '00000', $str_hex);
    $str_hex = str_ireplace('EE', '0000', $str_hex);
    $len_s = strlen($str_hex);
    if ($len_s % 2 !== 0) {
        $str_hex = substr($str_hex, 1);
    }
    //***1***
    $arr_hex = str_split($str_hex, 8);
    for ($j = 0; $j < count($arr_hex); $j++) {
        $arr_hex2[$j] = str_split($arr_hex[$j], 2);
        for ($k = 0; $k < 4; $k++) {
            $arr_dec[$j][$k] = sqrt(hexdec($arr_hex2[$j][$k]));
        }
        $dec[$j] = implode($arr_dec[$j]);
        $arr_str[$j] = chr($dec[$j]);
    }
    $restr = implode($arr_str);
    return $restr;
}
开发者ID:qianyuzhang,项目名称:studygit,代码行数:35,代码来源:decryption.php

示例9: __construct

 public function __construct($type = self::AND_BLOCK, $arg1 = null, $arg2 = null, $param = null)
 {
     if ($type === self::AND_BLOCK) {
         $this->and_block = $arg1;
     } else {
         if ($type === self::OR_BLOCK) {
             if (!is_array($arg1) || sizeof($arg1) < 2) {
                 throw new \ebi\exception\InvalidArgumentException('require multiple blocks');
             }
             foreach ($arg1 as $a) {
                 if (!$a->is_block()) {
                     throw new \ebi\exception\InvalidArgumentException('require multiple blocks');
                 }
             }
             $this->or_block = $arg1;
         } else {
             $this->arg1 = $arg1;
         }
     }
     $this->arg2 = $arg2;
     $this->type = $type;
     if ($param !== null) {
         if (!ctype_digit((string) $param)) {
             throw new \ebi\exception\InvalidArgumentException('`' . (string) $param . '` invalid param type');
         }
         $this->param = decbin($param);
     }
 }
开发者ID:tokushima,项目名称:ebi,代码行数:28,代码来源:Q.php

示例10: netmask2bitmask

/**
 * Get the number of netmask bits from a netmask in presentation format 
 * 
 * @param string $netmask Netmask in presentation format 
 *  
 * @return integer Number of mask bits 
 * @throws Exception 
 */
function netmask2bitmask($netmask)
{
    try {
        // Validate if $netmask is string
        if (gettype($netmask) !== "string") {
            throw new Exception("Netmask is not a string");
        }
        // Validate if $netmask is IPV4 or IPV6 address
        if (filter_var($netmask, FILTER_VALIDATE_IP) === false) {
            throw new Exception("Netmask is not a IPV4 or IPV6 valid address");
        }
        // Split string into octets or hextets
        $array = preg_split("/\\.|\\:/", $netmask);
        // Convert to binary, delete zeros and get length of resultant string
        if (filter_var($netmask, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === $netmask) {
            $func = function ($number) {
                return strlen(str_replace("0", "", decbin($number)));
            };
        } else {
            $func = function ($hexa) {
                return strlen(str_replace("0", "", decbin(base_convert($hexa, 16, 10))));
            };
        }
        return array_sum(array_map($func, $array));
    } catch (Exception $ex) {
        print $ex->getMessage();
    }
}
开发者ID:jufecara,项目名称:al-test2,代码行数:36,代码来源:ip_address.php

示例11: render

 /**
  * Prints base-2 (binary) representation of input string
  * @param string $m
  * @param int $rowLength
  * @param string $fillChar
  * @return string
  */
 public static function render($m, $rowLength = 8, $fillChar = ' ')
 {
     $j = 0;
     $bytes = '';
     $row = '';
     $res = '';
     $rowOffset = 0;
     for ($i = 0; $i < strlen($m); $i++) {
         $x = substr($m, $i, 1);
         if (ord($x) > 0x1f && ord($x) < 0x80) {
             $bytes .= $x;
         } else {
             $bytes .= '.';
         }
         $bin = sprintf("%08d", decbin(ord($x)));
         $row .= $bin . $fillChar;
         if (++$j == $rowLength) {
             $res .= sprintf("%06x", $rowOffset) . ": " . $row . ' ' . $bytes . PHP_EOL;
             $rowOffset += $rowLength;
             $bytes = '';
             $row = '';
             $j = 0;
         }
     }
     if ($j) {
         $res .= sprintf("%06x", $rowOffset) . ": " . $row . ' ' . str_repeat(' ', ($rowLength - strlen($bytes)) * 3) . $bytes . PHP_EOL;
     }
     return $res;
 }
开发者ID:martinlindhe,项目名称:php-debughelper,代码行数:36,代码来源:BinaryPrinter.php

示例12: returnAllergens

 function returnAllergens($input)
 {
     $allergens = array("eggs", "peanuts", "shellfish", "strawberries", "tomaters", "chocolate", "pollen", "cats");
     //define allergens
     $string = decbin($input);
     //converts to binary string<<<<<<<
     $string = strrev($string);
     //flips the string
     while (strlen($string) < count($allergens)) {
         $string .= "0";
     }
     $result = array();
     //define blank result array
     $array = str_split($string);
     // converts binary string into array. $string = "10010000" --> $string = array("1", "0", "0"...)
     foreach ($allergens as $index => $allergy) {
         //for each allergy in $allergens, while tracking its index...
         if ($array[$index] == '1') {
             //if your string array at the positiong of index...--> $string = array("1", "0", "0"...); == 1
             $result[$allergy] = true;
             //assigns into the $result array --> $result = array("eggs"=>true);
         } else {
             $result[$allergy] = false;
             //assigns into the $result array --> $result = array("eggs"=>false);
         }
     }
     return $result;
 }
开发者ID:joekarasek,项目名称:epicodus-php-allergen_decoder,代码行数:28,代码来源:Allergy.php

示例13: 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

示例14: solution

function solution($N)
{
    $new = decbin($N);
    $newarray = str_split($new);
    $i = [];
    $j = 0;
    foreach ($newarray as $key => $value) {
        if ($value == 0) {
            for ($x = 0; x < count($newarray); $x++) {
                if ($newarray[$x] == 0) {
                    $j = $j++;
                } else {
                    break;
                }
            }
            if ($j = count($newarray) - $key - 1) {
                $j = 0;
                $i[] = $j;
            } else {
                $i[] = $j;
            }
        }
        return max($i);
    }
}
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:25,代码来源:test.php

示例15: GetLevel

 public function GetLevel($level)
 {
     $levelString = decbin($level);
     //十进制转化二进制
     $levelArray = str_split($levelString);
     $len = count($levelArray);
     if ($len < $this->mLevelNums) {
         $head = array();
         for ($i = 0; $i < $this->mLevelNums - $len; $i++) {
             $head[$i] = 0;
         }
     } else {
         $head = array();
     }
     $levelArray = array_merge($head, $levelArray);
     $j = 0;
     //echo $this->mLevelNums;
     for ($i = $this->mLevelNums - 1; $i >= 0; $i--) {
         if ($levelArray[$i] == 1) {
             //拥有$i号权限
             $returnArray[$j] = $this->mLevelNums - $i - 1;
             $j++;
         } else {
             //不存在$i号权限
             continue;
         }
     }
     if ($j == 1) {
         return $returnArray[0];
     }
     return $j > 0 ? $returnArray : -1;
 }
开发者ID:xhsui,项目名称:ci_system,代码行数:32,代码来源:level.php


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