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
Nov 20 '05
33 2513
Acording to the help file . . .
Boolean variables are stored as 16-bit (2-byte) numbers
HTH
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2j******** *****@uni-berlin.de... * ka****@mailinat or.com (Ruffin Bailey) scripsit: 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).
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/>
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft .com> scripsit: Acording to the help file . . .
Boolean variables are stored as 16-bit (2-byte) numbers
You are right ;-).
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
This code disassembly appears to store the value '0' for False, if you
assign True to 'v' then the ldc.i4 line becomes ldc.i4.1.
So it would appear that in actual fact the binary storage for this type is
actually False=0 and True=1.
This seems to be converted differently when expressing as numeric types.
// Code size 5 (0x5)
.maxstack 1
.locals init ([0] bool v)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: nop
IL_0004: ret
} // end of method Form1::Button1_ Click
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2j******** *****@uni-berlin.de... * "One Handed Man \( OHM - Terry Burns \)" <news.microsoft .com> scripsit: Acording to the help file . . .
Boolean variables are stored as 16-bit (2-byte) numbers
You are right ;-).
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
Think about it...when you use numbers in VB w/o conversion, what data type is 1?
Integer. So, how many bytes does an integer use? In this case, you have an
integer value so converting that to binary as Herfried described now, because of
the compliment, also turns on the sign bit. Understand???
Mythran Hi Herfried,
This is how it is done for a boolean you need only one bulb which can be on and off. (or one bit in a computer)
:-)
Cor
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.
This code disassembly appears to store the value '0' for False, if you
assign True to 'v' then the ldc.i4 line becomes ldc.i4.1.
So it would appear that in actual fact the binary storage for this type is
actually False=0 and True=1.This code disassembly appears to store the
value '0' for False, if you
This seems to be converted differently when expressing as numeric types.
// Code size 5 (0x5)
.maxstack 1
.locals init ([0] bool v)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: nop
IL_0004: ret
} // end of method Form1::Button1_ Click
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Mythran" <ki********@hot mail.com> wrote in message
news:ex******** ******@tk2msftn gp13.phx.gbl... Think about it...when you use numbers in VB w/o conversion, what data type
is 1? Integer. So, how many bytes does an integer use? In this case, you have
an integer value so converting that to binary as Herfried described now,
because of the compliment, also turns on the sign bit. Understand???
Mythran
Hi Herfried,
This is how it is done for a boolean you need only one bulb which can be
on and off. (or one bit in a computer)
:-)
Cor
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.
Hi OHM,
The correct answer is in my opinion given by Greg Young.
What you than take as value is not important as long as true not is 0.
Cor
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft .com> scripsit: This code disassembly appears to store the value '0' for False, if you assign True to 'v' then the ldc.i4 line becomes ldc.i4.1.
So it would appear that in actual fact the binary storage for this type is actually False=0 and True=1.
This seems to be converted differently when expressing as numeric types.
// Code size 5 (0x5) .maxstack 1 .locals init ([0] bool v) IL_0000: nop IL_0001: ldc.i4.0 IL_0002: stloc.0 IL_0003: nop IL_0004: ret } // end of method Form1::Button1_ Click
Sure, 'False' is always 0, and 'True' is something <> 0. When doing a
'Not' on a 'Boolean' set to 'False' it's -1 because that's the complement of 0
interpreted as a signed short.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
My point was that true is not stored as -1, rather that it is stored as 1.
Which is different to what every one was saying. It is only when you convert
it that it to a numeric type that it becomes Minus 1.
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:Oh******** ******@TK2MSFTN GP12.phx.gbl... Hi OHM,
The correct answer is in my opinion given by Greg Young.
What you than take as value is not important as long as true not is 0.
Cor
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft .com> scripsit: My point was that true is not stored as -1, rather that it is stored as 1.
It's stored as -1 if you do a 'Not False'.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
"Ruffin Bailey" <ka****@mailina tor.com> wrote 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)?
Because the logical operators were always bit-wise operators.
That meant And, Or, Xor, and Not, could be used on numbers
as well as boolean conditional expressions.
7 And 3 = 3
if (2>0) And (4>2) then ...
It was an industry standard that False equaled 0, but what
value would satisfy these statements;
? = Not 0
0 = Not ?
The Not operator is just a bit-wise complement operator,
as it always had been, but because of that, there is only
one value that can be plugged into the statements above.
0 is a number where all bits are set to 0, so that means
its complement is a value whose bits are all set to 1.
In 2's complement notation (the format used to store signed
values in memory) a value with all its bits set to 1 equates
to -1.
LFS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: srommens |
last post by:
Hello,
When I try to do :
URI = <xsl:value-of select="//@URI"/><br/>
<xsl:if test = "//@URI != '5-42922'">not equal</xsl:if><br/>
<xsl:if test = "//@URI = '5-42922'">equal</xsl:if><br/>
The result is :
|
by: Scott Chapman |
last post by:
There seems to be an inconsistency here:
Python 2.3.2 (#1, Oct 3 2003, 19:04:58)
on linux2
>>> 1 == True
True
>>> 3 == True
False
>>> if 1: print "true"
....
|
by: Avin Patel |
last post by:
Hi,
Does the Double has the facilty to define -0.
If it has, "==" or System.Math.Sign() doesn't able to differentiate between -0 & 0.
i.e.
Double x = -0.0d
Double y = 0.0d
if(value == -0.0d) {//both x & y drops in this statement.
|
by: Marc |
last post by:
Hi,
I've been lurking on clc for a few months now, and want to start by
thanking the regulars here for opening my eyes to a whole new dimension
of "knowing c". Considering I had never even touched the standards a
year ago, though I graduated in embedded SW development...
Anyway, to the problem at hand: I've stumbled upon the following
construct at work recently, and cannot really make up my mind about the
standard's take on the matter.
|
by: Jason |
last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these
tests (below), and it doesn't make sense to me. False is equal to 0, and
that's fine. True should be equal to 1, but it's not. Actually, True
should be equal to anything but False, null, and 0. Is there a workaround
for this? Or do I need to change all my comparisons to = 1 instead of =
true?
response.write True = 1 'prints False
response.write True = 0 ...
| |
by: Peter Vestergaard |
last post by:
Hi
I have a project with quite a number of dialogs in it all with
Localizable=true, and all except one working fine.
But the one is causing me trouble because even though Localizable=true is
set, all strings (.Text properties and the like) are still written to
InitializeComponent() in the .cs file instead of to the .resx file.
I have tried setting the Localizable to false again,
saving/building/restarting studio, and then setting...
|
by: John Salerno |
last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part,
but it does in the second? Is the first statement something different?
False
print 'hi'
hi
Thanks.
|
by: Bernard.Mangay |
last post by:
The remainder is non zero due to rounding errors. How can I remove the
rounding errors?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |