CInt(True) // returns -1 CInt(False) // returns 0
这是其他语言中常见的吗?
我认为一个布尔值将为1如果为真,如果为假则为0。另外,有没有办法让Visual Basic将1赋值为true而不是赋值-1?
最好的解释,我可以找到VB的具体行为来自Wikipedia:
Boolean constant True has numeric value −1. This is because the Boolean data type is stored as a 16-bit signed integer. In this construct −1 evaluates to 16 binary 1s (the Boolean value True),and 0 as 16 0s (the Boolean value False). This is apparent when performing a Not operation on a 16 bit signed integer value 0 which will return the integer value −1,in other words True = Not False. This inherent functionality becomes especially useful when performing logical operations on the individual bits of an integer such as And,Or,Xor and Not.[4] This deFinition of True is also consistent with BASIC since the early 1970s Microsoft BASIC implementation and is also related to the characteristics of cpu instructions at the time.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。