1>> x行为 [英] 1>>x behaviour

查看:76
本文介绍了1>> x行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我对运算符>整数之间有一个小问题:确实

任何人都知道为什么,当我写的时候:

" 1> x",对于32和0的所有值,返回值为1

else(这不会伤害我,1会伤害我。)

当我做同样的事情:1L> x时,只有64的倍数这个。

我认为0是唯一可能的结果对于任何x 0.

为什么不是这样?以及如何纠正这一点 - 在一个

指令中,否则我通过以下方式完成:


long longFoo = intBar;

longFoo>> = x;

return(int)longFoo;


....但这看起来很奇怪。


提前感谢任何答案。

Hello,

I have a little question about operator >between integers: does
anyone know why, when I write:
"1 >x", the returned value is 1 for all values multiple of 32 and 0
else (this does not hurt me, 1 does).
When I do the same thing with : "1L >x", only multiples of 64 do
this.
I thought 0 was the only possible result for any x 0.
Why is it not the case ? And how to correct this simply -- in one
instruction, else I did it by:

long longFoo = intBar;
longFoo >>= x;
return (int) longFoo;

.... but this looks weird to do this.

Thanks in advance to any answer.

推荐答案

嗨Vivien,


使用x操作数的最低5位进行移位操作

Int32,最低6位用于Int64。


1> 32与1> 0

相同On Thu,2006年11月23日12:20:55 +0100,Vivien Parlat< po **** @ gmail.comwrote:
Hi Vivien,

The shift operation is done using the lowest 5 bits of the x operand for
Int32, and lowest 6 bits for Int64.

1 >32 is the same as 1 >0
On Thu, 23 Nov 2006 12:20:55 +0100, Vivien Parlat <po****@gmail.comwrote:

您好,


我对运算符>整数之间有一个小问题:确实

任何人知道为什么,当我写道:

" 1> x"时,返回值为1表示所有值的倍数32和0

else(这不会伤害我,1确实)。

当我这样做的时候事情:1L> x,只有64的倍数这个。

我认为0是任何x 0的唯一可能结果。

为什么不是这样?以及如何纠正这一点 - 在一个

指令中,否则我通过以下方式完成:


long longFoo = intBar;

longFoo>> = x;

return(int)longFoo;


...但这看起来很奇怪。


预先感谢任何答案。
Hello,

I have a little question about operator >between integers: does
anyone know why, when I write:
"1 >x", the returned value is 1 for all values multiple of 32 and 0
else (this does not hurt me, 1 does).
When I do the same thing with : "1L >x", only multiples of 64 do
this.
I thought 0 was the only possible result for any x 0.
Why is it not the case ? And how to correct this simply -- in one
instruction, else I did it by:

long longFoo = intBar;
longFoo >>= x;
return (int) longFoo;

... but this looks weird to do this.

Thanks in advance to any answer.




-

快乐编码!

Morten Wennevik [C#MVP]



--
Happy Coding!
Morten Wennevik [C# MVP]


那是一个错误吗?


" Morten Wennevik" < Mo ************ @ hotmail.comwrote in message

news:op *************** @ tr024。 bouvet.no ...

嗨Vivien,


使用x操作数的最低5位完成移位操作

Int32,Int64最低6位。


1> 32与1> 0相同

2006年11月23日星期四12 :20:55 + 0100,Vivien Parlat< po **** @ gmail.comwrote:
So is that a bug?

"Morten Wennevik" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Vivien,

The shift operation is done using the lowest 5 bits of the x operand for
Int32, and lowest 6 bits for Int64.

1 >32 is the same as 1 >0
On Thu, 23 Nov 2006 12:20:55 +0100, Vivien Parlat <po****@gmail.comwrote:

您好,


我对运算符>整数之间有一个小问题:确实

任何人都知道为什么,当我写:

" 1> x"时,返回的值是1表示所有值的倍数32和0

else(这不会伤害我,1会这样做。)

当我做同样的事情:" 1L> x",只有64的倍数。

这个。

我认为0是任何x 0唯一可能的结果。

为什么会这样不是这样的吗?以及如何纠正这一点 - 在一个

指令中,否则我通过以下方式完成:


long longFoo = intBar;

longFoo>> = x;

return(int)longFoo;


...但这看起来很奇怪。


预先感谢任何答案。
Hello,

I have a little question about operator >between integers: does
anyone know why, when I write:
"1 >x", the returned value is 1 for all values multiple of 32 and 0
else (this does not hurt me, 1 does).
When I do the same thing with : "1L >x", only multiples of 64 do
this.
I thought 0 was the only possible result for any x 0.
Why is it not the case ? And how to correct this simply -- in one
instruction, else I did it by:

long longFoo = intBar;
longFoo >>= x;
return (int) longFoo;

... but this looks weird to do this.

Thanks in advance to any answer.




-

快乐编码!

Morten Wennevik [C#MVP]



--
Happy Coding!
Morten Wennevik [C# MVP]


星期五,2006年11月24日10:14:50 +0100,Jay< nospamwrote:
On Fri, 24 Nov 2006 10:14:50 +0100, Jay <nospamwrote:

那是一个错误吗?
So is that a bug?



这是设计的。当你考虑它时,将32位整数和

移动超过31个位置是没有任何意义的。

http://msdn2.microsoft.com/en-us/library/xt18et0d.aspx

-

快乐编码!

Morten Wennevik [C#MVP]

It''s by design. When you think about it, shifting a 32 bit integer with
anything more than 31 places doesn''t make any sense.

http://msdn2.microsoft.com/en-us/library/xt18et0d.aspx
--
Happy Coding!
Morten Wennevik [C# MVP]


这篇关于1&gt;&gt; x行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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