令人困惑的>>结果 [英] confusing >> results

查看:56
本文介绍了令人困惑的>>结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用>>通常将位移位到右侧x次,其中x

由程序员指定。例如,0x40000000>> 8收益

0x00400000。这让我很奇怪......为什么不会发生同样的事情

with 0x80000000>> 8?它产生的数字是0xff800000 - 而不是


< ;?

echo sprintf(''%08x'',0x40000000>> 8)。 \ n" ;;

echo sprintf(''%08x'',0x80000000>> 8);

?>


无论如何,任何想法?

Using >> normally shifts bits to the right x number of times, where x
is specified by the programmer. As an example, 0x40000000 >> 8 yields
0x00400000. This makes me wonder... why doesn''t the same thing happen
with 0x80000000 >> 8? The number it yields is 0xff800000 - not
0x00800000. The following script better demonstrates this:

<?
echo sprintf(''%08x'',0x40000000 >> 8)."\n";
echo sprintf(''%08x'',0x80000000 >> 8);
?>

Anyway, any ideas?

推荐答案

yawnmoth写道:
yawnmoth wrote:
使用>>通常将位移位到右侧x次,其中x
由程序员指定。例如,0x40000000>> 8收益率
0x00400000。这让我很奇怪......为什么不会发生同样的事情
与0x80000000>> 8?它产生的数字是0xff800000 - 而不是0x00800000。以下脚本更好地说明了这一点:

<?
echo sprintf(''%08x'',0x40000000>> 8)。" \ n" ;;
echo sprintf(''%08x'',0x80000000>> 8);
?>

无论如何,有什么想法?
Using >> normally shifts bits to the right x number of times, where x
is specified by the programmer. As an example, 0x40000000 >> 8 yields
0x00400000. This makes me wonder... why doesn''t the same thing happen
with 0x80000000 >> 8? The number it yields is 0xff800000 - not
0x00800000. The following script better demonstrates this:

<?
echo sprintf(''%08x'',0x40000000 >> 8)."\n";
echo sprintf(''%08x'',0x80000000 >> 8);
?>

Anyway, any ideas?



我的猜测是PHP看到0x8000000为* signed *整数



My guess is that PHP sees 0x8000000 as a *signed* integer


Palle Hansen写道:
Palle Hansen wrote:
yawnmoth写道:
yawnmoth wrote:
使用>>通常将位移位到右侧x次,其中x
由程序员指定。例如,0x40000000>> 8收益率
0x00400000。这让我很奇怪......为什么不会发生同样的事情
与0x80000000>> 8?它产生的数字是0xff800000 - 而不是0x00800000。以下脚本更好地说明了这一点:

<?
echo sprintf(''%08x'',0x40000000>> 8)。" \ n" ;;
echo sprintf(''%08x'',0x80000000>> 8);
?>

无论如何,有什么想法?
Using >> normally shifts bits to the right x number of times, where x
is specified by the programmer. As an example, 0x40000000 >> 8 yields
0x00400000. This makes me wonder... why doesn''t the same thing happen
with 0x80000000 >> 8? The number it yields is 0xff800000 - not
0x00800000. The following script better demonstrates this:

<?
echo sprintf(''%08x'',0x40000000 >> 8)."\n";
echo sprintf(''%08x'',0x80000000 >> 8);
?>

Anyway, any ideas?


我的猜测是PHP看到0x8000000作为* signed *整数



My guess is that PHP sees 0x8000000 as a *signed* integer




好​​像你是对的,Palle。


我用这段代码测试过:


<?php

header(''Content-Type:text / plain'');



Seems like you''re right, Palle.

I tested with this code:

<?php
header(''Content-Type: text/plain'');


t = 0x80000000;

echo
t = 0x80000000;
echo


这篇关于令人困惑的&gt;&gt;结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆