按位操作限制? [英] Bitwise Operation limitation?

查看:50
本文介绍了按位操作限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一些大整数进行逐位运算。


例如,


Response.Write CBool​​(2 AND 2 ^ 30)''返回False

Response.Write CBool​​(2和2 ^ 31)''崩溃!


看起来AND运算符只能处理整数高达2147483647?

有没有办法让AND运算符使用更大的整数,例如

double数据类型?

解决方案

David R.写道:

我想对一些大整数进行逐位运算。

例如,

Response.Write CBool​​(2和2 ^ 30)''返回False
Response.Write CBool​​(2 AND 2 ^ 31)''崩溃!

看起来像AND运算符只能处理整数到2147483647?有没有办法让AND运算符以更大的整数运行
,例如double数据类型?




单程:

<%@ Language = VBScript%><%


Response.Write(JSAnd(1234562,2 ^ 36-1))


%>< script runat =" server" language =" jscript">

函数JSAnd(a,b){return a& b}

< / script>


-

戴夫安德森


将以每封邮件


500的费用阅读未经请求的商业电子邮件。使用

此电子邮件地址即表示同意这些条款。请不要直接联系

我或要求我直接与您联系以获取帮助。如果你的问题值得询问,那就值得发帖了。


> Response.Write CBool​​(2 AND 2 ^ 31)''崩溃了!

看起来AND运算符只能处理高达2147483647的整数?




这与And运算符无关。


VBScript使用的最大整数长度是4字节长或32位。

但是这是一个有符号整数,所以范围是2 ^ 31-1到 - (2 ^ 31)。


试试这个: -


Response.Write CBool​​(2和& h80000000)


如果你正在进行按位操作而你想翻转最后一位使用: -


x = x或& H80000000''On

x = x和& H7FFFFFFF''关闭


Anthony。


I want to do bitwise operation on some large integers.

For example,

Response.Write CBool(2 AND 2^30) '' returns False
Response.Write CBool(2 AND 2^31) '' CRASHED!

Looks like the AND operator can only deal with integers up to 2147483647?
Is there a way to make the AND operator work with larger integers, such as
the double datatype?

解决方案

David R. wrote:

I want to do bitwise operation on some large integers.

For example,

Response.Write CBool(2 AND 2^30) '' returns False
Response.Write CBool(2 AND 2^31) '' CRASHED!

Looks like the AND operator can only deal with integers up
to 2147483647? Is there a way to make the AND operator work
with larger integers, such as the double datatype?



One way:

<%@ Language=VBScript %><%

Response.Write(JSAnd(1234562,2^36-1))

%><script runat="server" language="jscript">
function JSAnd(a,b) { return a & b }
</script>

--
Dave Anderson

Unsolicited commercial email will be read at a cost of


500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it''s worth posting.


> Response.Write CBool(2 AND 2^31) '' CRASHED!

Looks like the AND operator can only deal with integers up to 2147483647?



This has nothing to do with the And operator.

The maximum length of integer that VBScript uses is 4-bytes long or 32 bits.
However this is a signed integer so the range is 2^31-1 down to -(2^31).

Try this:-

Response.Write CBool(2 and &h80000000)

If you are doing bitwise operations and you want to flip the top bit use:-

x = x Or &H80000000 '' On
x = x And &H7FFFFFFF '' Off

Anthony.


这篇关于按位操作限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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