为什么在VB中减一(-1)等于真? [英] Why is minus one (-1) equal to true in VB again?

查看:146
本文介绍了为什么在VB中减一(-1)等于真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能发誓我在AppDev课程期间给了一个解释

之前的VB6,但不记得答案了。为什么在Visual Basic(现在是VB.NET)中-1是真的

?比特标志看起来应该是

总是0或1对我来说...(并不是说我现在还没有用VB足够长的时间来了解更多) 。


很抱歉,但是为什么-1 =真的?

谷歌是一件困难的事情!


Ruffin Bailey

I coulda sworn I was given an explanation during an AppDev class years
ago for VB6, but don''t recall the answer. Why is it that -1 is True
in Visual Basic (and now VB.NET)? Bit flags seem like they should
always be 0 or 1 to me... (not that I haven''t used VB long enough by
now to know better).

Sorry to pester, but "why is -1 = true?" is a difficult thing to
Google!

Ruffin Bailey

推荐答案

HI Ruffin,


为什么要开始计算语句中的零,并且正常计数

一。只是因为改变那些东西是非常困难的我假设

并保持向后兼容。


(我认为当计数从一开始计算时也更容易设置

假为零)。


只是我的想法。


Cor
HI Ruffin,

Why start counting in programlanguages with zero and in normal counting with
one. Just because it is terrible difficult to change those things I assume
and keep it backwards compatible.

(I think that when the counting would start at one it was also easier to set
the false to zero).

Just my thought.

Cor
我可以发誓我在AppDev课程期间获得了VB6的解释,但不记得答案。为什么在Visual Basic(现在的VB.NET)中-1是真的?比特标志看起来应该总是0或1对我来说...(并不是说我现在还没有使用VB足够长的时间来了解更好)。
抱歉纠缠,但为什么-1 =真?对谷歌来说是一件困难的事情!

Ruffin Bailey
I coulda sworn I was given an explanation during an AppDev class years
ago for VB6, but don''t recall the answer. Why is it that -1 is True
in Visual Basic (and now VB.NET)? Bit flags seem like they should
always be 0 or 1 to me... (not that I haven''t used VB long enough by
now to know better).

Sorry to pester, but "why is -1 = true?" is a difficult thing to
Google!

Ruffin Bailey



我没有给你一个答案,但我确实有意见。那就是

你应该把选项严格打开,这样就像

如果-1 = True那么


永远不会编译。你不应该依赖于后期绑定来编码

将整数转换为布尔值等。


Ruffin Bailey < KA **** @ mailinator.com>在消息中写道

news:fd ************************** @ posting.google.c om ...
I don''t have an answer for you, but I do have an opinion. And that is that
you should turn option strict on, and that way something like
If -1 = True Then

Would never even compile. You shouldn''t be coding relying on late binding to
turn integers into booleans, etc.

"Ruffin Bailey" <ka****@mailinator.com> wrote in message
news:fd**************************@posting.google.c om...
我可以发誓我在AppDev课程期间给了VB6一个解释,但是不记得答案了。为什么在Visual Basic(现在的VB.NET)中-1是真的?比特标志看起来应该总是0或1对我来说...(并不是说我现在还没有使用VB足够长的时间来了解更好)。
抱歉纠缠,但为什么-1 =真?对谷歌来说是一件困难的事情!

Ruffin Bailey
I coulda sworn I was given an explanation during an AppDev class years
ago for VB6, but don''t recall the answer. Why is it that -1 is True
in Visual Basic (and now VB.NET)? Bit flags seem like they should
always be 0 or 1 to me... (not that I haven''t used VB long enough by
now to know better).

Sorry to pester, but "why is -1 = true?" is a difficult thing to
Google!

Ruffin Bailey



* ka **** @ mailinator.com (Ruffin Bailey)scripsit:
* ka****@mailinator.com (Ruffin Bailey) scripsit:
我能发誓我在AppDev课程期间获得了解释<之前的VB6,但不记得答案了。为什么在Visual Basic(现在的VB.NET)中-1是真的?比特标志看起来应该总是0或1对我来说...(并不是说我现在还没有使用VB足够长的时间来了解更好)。
I coulda sworn I was given an explanation during an AppDev class years
ago for VB6, but don''t recall the answer. Why is it that -1 is True
in Visual Basic (and now VB.NET)? Bit flags seem like they should
always be 0 or 1 to me... (not that I haven''t used VB long enough by
now to know better).



布尔值存储为32位整数。


''False''= 000000 .... 000(BIN)= 0(DEC )

''True''= 111111 .... 111(BIN)= -1(DEC)


第一位是符号位,如果它设置为1表示

负数。


-

Herfried K. Wagner [MVP ]

< URL:http://dotnet.mvps.org/>



Booleans are stored as 32-bit-integers.

''False'' = 000000....000 (BIN) = 0 (DEC)
''True'' = 111111....111 (BIN) = -1 (DEC)

The first bit is the sign bit, if it''s set to 1 that indicates a
negative number.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


这篇关于为什么在VB中减一(-1)等于真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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