PHP中位数不一样的数字的位操作
发布于 2007-04-16 17:12 8 阅读:44,826 评论:8 标签: php 位操作

一直以来对算法性的东西了解的少,这不今天又遇见问题。看google黑板报一个数学之美的文章简单之美:布尔代数和搜索引擎的索引,觉得对二进制的运算练习很少,于是拿来练手。

当位数不一样时运行的结果已然不是1和0的组合了

例如:

CODE:
$a 1001;
$b 111000;

$c $a $b ;
$d $a $b ;
$e $a $b ;
echo 
$c." ".$d." ".$e;
?>

结果是 :392 111609 111217

不明白其中的道理,转而向喜悦村求救。得到fly512给的答案:

CODE:
$a  1001;
$a1 base_convert$a102) ;        //把10进制转化为2进制
$b  111000;
$b1 base_convert$b102);       //把10进制转化为2进制
$c $a $b ;

echo 
$c.'
'
;//十进制结果
echo base_convert$c102); //把$c转化为2进制
echo $a1." ".$b1."
"
;
/******************
00000001111101001   //$a1的值,也就是$a的2进制,高位加0,与$b的2进制对齐
11011000110011000   //$b1的值,也就是$b的2进制
00000000110001000  //相与的结果,全1则为1,否则为0
********************/
?>
不由得为自己的函数知识感到惭愧。。。。。

终于又学了一课,这也是我一直弄不明白的问题

by winw 2012-02-28 22:52:34
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
不是的

PHP好像是自动识别的
你用01组合,位数一样的话就是2进制了

by 芽雨 2007-04-22 18:37:43
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
这个!!

PHP写的整型变量默认的是10进制的?这样的话相与时自然要化为2进制。

by 彳亍 2007-04-22 17:44:04
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
hehe

正则可以说不会,呵呵,不过可以利用数据库分开放置,一个摘要用于首页显示,一个详细内容用于详细叶面。想要在首页显示的图片可以放到摘要中。
呵呵,一种笨的方法。有的博客程序就是这样,感觉不怎么样?
或者利用分页[pge]将叶面分割为前台和详细叶面,应该感觉不错,没有测试~~~

by mdy 2007-04-19 13:48:23
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
可以专门针对<img>

可以考虑专门针对<img>标签做个过滤程序嘛

by yayu 2007-04-19 12:22:41
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
hehe,回复挺快

这是中文截取字符函数,不是这个

因为假如你的博客内容里面是html,例如:<img src="pic.gif"〉...
截取的时候会截取成<img src= 后面没了,当然,也可能发生在其他的html语法中,所以我的博客是利用strip_tags去除html,然后截取,问题没了,但是想显示个图片,不能了,当然利用strip_tags只留下img也行,但是截取的时候不好掌握??困惑~~~~~~~

by mdy 2007-04-19 10:10:02
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
substr和ord

function gbSubstr_blog_article($str,$strlen=1000,$other=true)
{
$j = 0;

for($i=0;$i<$strlen;$i++)
{
if(ord(substr($str,$i,1))>0xa0) $j++;
}

if($j%2!=0) $strlen--;

$rstr=substr($str,0,$strlen);

if (strlen($str)>$strlen && $other) $rstr.='………';

return $rstr;
}

by yayu 2007-04-19 09:08:18
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172
博客首页如何截取

雨:你的博客首页内容是如何截取并显示的,是利用substr??

by mdy 2007-04-19 08:57:09
Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 154

Warning: Trying to access array offset on value of type bool in /opt/bitnami/apache/htdocs/workingsmarty/templates_c/e21e83752348f01f75c472238af0e4512d51cc32_0.file.left_look.html.php on line 172