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 2512
No, it is stored as a +1 one the stack.
--
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: 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/>
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. Additionally, by storing the Boolean value as all 1's or all 0's, you get an additional performance gain when dealing with IO, as you can ignore the Byte Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward.
What the heck is middle endian? ;^) The other two, being a Mac user
when I'm not at work, have pretty clear meanings.
But this makes some sense for why things are -1 and not 1 or (as you
point out below) -0. False is "everything off" and True is "every
switch on". And 11111111 = -1 -- but it's not -1 in signed Integers,
which is confusing. That'd be 10000001, right?
IF you did have a 1 Bit signed integer type, if the value was not 0, it would be -1 (or -0, but that's a discussion for another day)
Actually that makes sense and we can dispense with the new discussion!
;^) That's part of my original wondering about why it works as it
does. 10000000 in a signed byte would be "negative 0000000". I've
done just enough assembly
(http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a
decent handle on how the bits work. It would have made sense to me to
have "official True" be 10000000 (a quick rol to check) or 00000001
(1=1), but 10000001 (signed -1) didn't make much sense at all.
Now, again, 11111111 is -1 in unsigned bytes, right? That makes some
sense as True.
Though admittedly I'm starting to wonder if I haven't got negative
signed byte expressions off in my head, as everyone seems to accept
11111111 (realizing I'm simplifying everything using one byte instead
of 32 bit fun) as -1 *signed*. ???
A Boolean evaluation of an expression is actually a double negative. If an expression does not evaluate to False(0), then it must be True. So all non zero values are True.
That's been mentioned a few times, and immediately after posting it
occurred to me to check and see what CBool(1) gave me (True). But why
CInt(True) gave me -1 for "official True" was a mystery. I think the
"all bits True in the byte" makes the most sense. Whether that's -1
in signed- or unsigned-land, I'll straighten out in my head later!
Thanks everyone for the posts. Feel free to lambast my relatively
weak grasping of the situation! If I didn't have so many bad habits
already, the "Turn on Option Strict" post my be the best suggestion of
them all.
Ruffin Bailey
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. Additionally, by storing the Boolean value as all 1's or all 0's, you get an additional performance gain when dealing with IO, as you can ignore the Byte Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward.
What the heck is middle endian? ;^) The other two, being a Mac user
when I'm not at work, have pretty clear meanings.
But this makes some sense for why things are -1 and not 1 or (as you
point out below) -0. False is "everything off" and True is "every
switch on". And 11111111 = -1 -- but it's not -1 in signed Integers,
which is confusing. That'd be 10000001, right?
IF you did have a 1 Bit signed integer type, if the value was not 0, it would be -1 (or -0, but that's a discussion for another day)
Actually that makes sense and we can dispense with the new discussion!
;^) That's part of my original wondering about why it works as it
does. 10000000 in a signed byte would be "negative 0000000". I've
done just enough assembly
(http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a
decent handle on how the bits work. It would have made sense to me to
have "official True" be 10000000 (a quick rol to check) or 00000001
(1=1), but 10000001 (signed -1) didn't make much sense at all.
Now, again, 11111111 is -1 in unsigned bytes, right? That makes some
sense as True.
Though admittedly I'm starting to wonder if I haven't got negative
signed byte expressions off in my head, as everyone seems to accept
11111111 (realizing I'm simplifying everything using one byte instead
of 32 bit fun) as -1 *signed*. ???
A Boolean evaluation of an expression is actually a double negative. If an expression does not evaluate to False(0), then it must be True. So all non zero values are True.
That's been mentioned a few times, and immediately after posting it
occurred to me to check and see what CBool(1) gave me (True). But why
CInt(True) gave me -1 for "official True" was a mystery. I think the
"all bits True in the byte" makes the most sense. Whether that's -1
in signed- or unsigned-land, I'll straighten out in my head later!
Thanks everyone for the posts. Feel free to lambast my relatively
weak grasping of the situation! If I didn't have so many bad habits
already, the "Turn on Option Strict" post my be the best suggestion of
them all.
Ruffin Bailey
Ruffin,
Middle Endian is when you fiddle with the byte ordering in the Word.
1-2-3-4 Big Endian
4-3-2-1 Little Endian
3-4-1-2 / 2-1-3-4 Middle Endian
Take a look at: http://en.wikipedia.org/wiki/Endianness
This works best on 16Bit computers living in the 32Bit world.
In fact, some IO in Windows still works this way.
Your confusion on the representation of Bits and why -1=11111111 and not
10000001 is because you are thinking as a human :)
Binary math is simplified if you use "Two's Complement" representation of the
binary for negative numbers.
That is how computers like to do it.
This would make the representation backwards from what you would think.
Basically, take a positive representation, flip the bits, then add 1.
Take the value +1 = 0000001
Flip the bits to make negative = 1111110
Add 1 = 11111111
So 11111111 = -1 in a Signed Byte
In an Unsigned Byte, it would be 255
Hope this helps to clear things up a little.
Gerald
"Ruffin Bailey" <ka****@mailina tor.com> wrote in message
news:fd******** *************** ***@posting.goo gle.com... "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message
news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. Additionally, by storing the Boolean value as all 1's or all 0's, you get an additional performance gain when dealing with IO, as you can ignore the Byte Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward.
What the heck is middle endian? ;^) The other two, being a Mac user when I'm not at work, have pretty clear meanings.
But this makes some sense for why things are -1 and not 1 or (as you point out below) -0. False is "everything off" and True is "every switch on". And 11111111 = -1 -- but it's not -1 in signed Integers, which is confusing. That'd be 10000001, right?
IF you did have a 1 Bit signed integer type, if the value was not 0, it
would be -1 (or -0, but that's a discussion for another day)
Actually that makes sense and we can dispense with the new discussion! ;^) That's part of my original wondering about why it works as it does. 10000000 in a signed byte would be "negative 0000000". I've done just enough assembly (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a decent handle on how the bits work. It would have made sense to me to have "official True" be 10000000 (a quick rol to check) or 00000001 (1=1), but 10000001 (signed -1) didn't make much sense at all.
Now, again, 11111111 is -1 in unsigned bytes, right? That makes some sense as True.
Though admittedly I'm starting to wonder if I haven't got negative signed byte expressions off in my head, as everyone seems to accept 11111111 (realizing I'm simplifying everything using one byte instead of 32 bit fun) as -1 *signed*. ???
A Boolean evaluation of an expression is actually a double negative. If an expression does not evaluate to False(0), then it must be True. So all
non zero values are True.
That's been mentioned a few times, and immediately after posting it occurred to me to check and see what CBool(1) gave me (True). But why CInt(True) gave me -1 for "official True" was a mystery. I think the "all bits True in the byte" makes the most sense. Whether that's -1 in signed- or unsigned-land, I'll straighten out in my head later!
Thanks everyone for the posts. Feel free to lambast my relatively weak grasping of the situation! If I didn't have so many bad habits already, the "Turn on Option Strict" post my be the best suggestion of them all.
Ruffin Bailey
As a side note, this is what makes the topic of -0 interesting.
If you do some research, you will see that when using two's complement, you get
a couple of interesting exceptions to the rule that would seemingly break
things. But when they are resolved, they actually end up being what you wanted
in the first place.
-0 and +128 would be of significant note.
This is why a signed byte ranges from -128 to +127.
And not +- 127 or +- 128.
Gerald
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message
news:eq******** ******@TK2MSFTN GP10.phx.gbl... Ruffin,
Middle Endian is when you fiddle with the byte ordering in the Word. 1-2-3-4 Big Endian 4-3-2-1 Little Endian 3-4-1-2 / 2-1-3-4 Middle Endian
Take a look at: http://en.wikipedia.org/wiki/Endianness
This works best on 16Bit computers living in the 32Bit world. In fact, some IO in Windows still works this way.
Your confusion on the representation of Bits and why -1=11111111 and not 10000001 is because you are thinking as a human :) Binary math is simplified if you use "Two's Complement" representation of the binary for negative numbers. That is how computers like to do it. This would make the representation backwards from what you would think. Basically, take a positive representation, flip the bits, then add 1. Take the value +1 = 0000001 Flip the bits to make negative = 1111110 Add 1 = 11111111
So 11111111 = -1 in a Signed Byte In an Unsigned Byte, it would be 255
Hope this helps to clear things up a little.
Gerald
"Ruffin Bailey" <ka****@mailina tor.com> wrote in message news:fd******** *************** ***@posting.goo gle.com... "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. Additionally, by storing the Boolean value as all 1's or all 0's, you get
an additional performance gain when dealing with IO, as you can ignore the
Byte Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward.
What the heck is middle endian? ;^) The other two, being a Mac user when I'm not at work, have pretty clear meanings.
But this makes some sense for why things are -1 and not 1 or (as you point out below) -0. False is "everything off" and True is "every switch on". And 11111111 = -1 -- but it's not -1 in signed Integers, which is confusing. That'd be 10000001, right?
IF you did have a 1 Bit signed integer type, if the value was not 0, it would be -1 (or -0, but that's a discussion for another day)
Actually that makes sense and we can dispense with the new discussion! ;^) That's part of my original wondering about why it works as it does. 10000000 in a signed byte would be "negative 0000000". I've done just enough assembly (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a decent handle on how the bits work. It would have made sense to me to have "official True" be 10000000 (a quick rol to check) or 00000001 (1=1), but 10000001 (signed -1) didn't make much sense at all.
Now, again, 11111111 is -1 in unsigned bytes, right? That makes some sense as True.
Though admittedly I'm starting to wonder if I haven't got negative signed byte expressions off in my head, as everyone seems to accept 11111111 (realizing I'm simplifying everything using one byte instead of 32 bit fun) as -1 *signed*. ???
A Boolean evaluation of an expression is actually a double negative. If an expression does not evaluate to False(0), then it must be True. So
all non zero values are True.
That's been mentioned a few times, and immediately after posting it occurred to me to check and see what CBool(1) gave me (True). But why CInt(True) gave me -1 for "official True" was a mystery. I think the "all bits True in the byte" makes the most sense. Whether that's -1 in signed- or unsigned-land, I'll straighten out in my head later!
Thanks everyone for the posts. Feel free to lambast my relatively weak grasping of the situation! If I didn't have so many bad habits already, the "Turn on Option Strict" post my be the best suggestion of them all.
Ruffin Bailey
All of this is a bit superfluous really. I have discovered that the
compiler stores a +1 for True on the stack for a boolean type 'True' and 0
for a Boolean Type 'False'
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. As a side note, this is what makes the topic of -0 interesting. If you do some research, you will see that when using two's complement,
you get a couple of interesting exceptions to the rule that would seemingly break things. But when they are resolved, they actually end up being what you
wanted in the first place. -0 and +128 would be of significant note. This is why a signed byte ranges from -128 to +127. And not +- 127 or +- 128.
Gerald
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:eq******** ******@TK2MSFTN GP10.phx.gbl... Ruffin,
Middle Endian is when you fiddle with the byte ordering in the Word. 1-2-3-4 Big Endian 4-3-2-1 Little Endian 3-4-1-2 / 2-1-3-4 Middle Endian
Take a look at: http://en.wikipedia.org/wiki/Endianness
This works best on 16Bit computers living in the 32Bit world. In fact, some IO in Windows still works this way.
Your confusion on the representation of Bits and why -1=11111111 and not 10000001 is because you are thinking as a human :) Binary math is simplified if you use "Two's Complement" representation
of the binary for negative numbers. That is how computers like to do it. This would make the representation backwards from what you would think. Basically, take a positive representation, flip the bits, then add 1. Take the value +1 = 0000001 Flip the bits to make negative = 1111110 Add 1 = 11111111
So 11111111 = -1 in a Signed Byte In an Unsigned Byte, it would be 255
Hope this helps to clear things up a little.
Gerald
"Ruffin Bailey" <ka****@mailina tor.com> wrote in message news:fd******** *************** ***@posting.goo gle.com... "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. > Additionally, by storing the Boolean value as all 1's or all 0's,
you get an > additional performance gain when dealing with IO, as you can ignore
the Byte > Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or
backward. What the heck is middle endian? ;^) The other two, being a Mac user when I'm not at work, have pretty clear meanings.
But this makes some sense for why things are -1 and not 1 or (as you point out below) -0. False is "everything off" and True is "every switch on". And 11111111 = -1 -- but it's not -1 in signed Integers, which is confusing. That'd be 10000001, right?
> IF you did have a 1 Bit signed integer type, if the value was not 0,
it would > be -1 (or -0, but that's a discussion for another day)
Actually that makes sense and we can dispense with the new discussion! ;^) That's part of my original wondering about why it works as it does. 10000000 in a signed byte would be "negative 0000000". I've done just enough assembly (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a decent handle on how the bits work. It would have made sense to me to have "official True" be 10000000 (a quick rol to check) or 00000001 (1=1), but 10000001 (signed -1) didn't make much sense at all.
Now, again, 11111111 is -1 in unsigned bytes, right? That makes some sense as True.
Though admittedly I'm starting to wonder if I haven't got negative signed byte expressions off in my head, as everyone seems to accept 11111111 (realizing I'm simplifying everything using one byte instead of 32 bit fun) as -1 *signed*. ???
> A Boolean evaluation of an expression is actually a double negative. > If an expression does not evaluate to False(0), then it must be
True. So all non > zero values are True.
That's been mentioned a few times, and immediately after posting it occurred to me to check and see what CBool(1) gave me (True). But why CInt(True) gave me -1 for "official True" was a mystery. I think the "all bits True in the byte" makes the most sense. Whether that's -1 in signed- or unsigned-land, I'll straighten out in my head later!
Thanks everyone for the posts. Feel free to lambast my relatively weak grasping of the situation! If I didn't have so many bad habits already, the "Turn on Option Strict" post my be the best suggestion of them all.
Ruffin Bailey
Agreed. I haven't investigated the actual implementation in dotNet or the other
various languages.
This has become more about the mechanics of it all as opposed to the
implementation.
Although if one was to ask me to guess what the implementation would have been,
my guess would not have been +1.
So I do find the actual implementation to be interesting.
In the end, I think Greg deserves the vote for the "best" answer.
FALSE = 0
TRUE = !FALSE
But as it turns out, how you actually implement that can vary.
Gerald
There are 10 kinds of people in the world.
Those that understand Binary, and those that do not.
(oldie but goodie, and appropriate here)
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:OX******** ******@TK2MSFTN GP12.phx.gbl... All of this is a bit superfluous really. I have discovered that the compiler stores a +1 for True on the stack for a boolean type 'True' and 0 for a Boolean Type 'False'
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. As a side note, this is what makes the topic of -0 interesting. If you do some research, you will see that when using two's complement, you get a couple of interesting exceptions to the rule that would seemingly break things. But when they are resolved, they actually end up being what you wanted in the first place. -0 and +128 would be of significant note. This is why a signed byte ranges from -128 to +127. And not +- 127 or +- 128.
Gerald
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:eq******** ******@TK2MSFTN GP10.phx.gbl... Ruffin,
Middle Endian is when you fiddle with the byte ordering in the Word. 1-2-3-4 Big Endian 4-3-2-1 Little Endian 3-4-1-2 / 2-1-3-4 Middle Endian
Take a look at: http://en.wikipedia.org/wiki/Endianness
This works best on 16Bit computers living in the 32Bit world. In fact, some IO in Windows still works this way.
Your confusion on the representation of Bits and why -1=11111111 and not 10000001 is because you are thinking as a human :) Binary math is simplified if you use "Two's Complement" representation of the binary for negative numbers. That is how computers like to do it. This would make the representation backwards from what you would think. Basically, take a positive representation, flip the bits, then add 1. Take the value +1 = 0000001 Flip the bits to make negative = 1111110 Add 1 = 11111111
So 11111111 = -1 in a Signed Byte In an Unsigned Byte, it would be 255
Hope this helps to clear things up a little.
Gerald
"Ruffin Bailey" <ka****@mailina tor.com> wrote in message news:fd******** *************** ***@posting.goo gle.com... > "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. > > Additionally, by storing the Boolean value as all 1's or all 0's, you get an > > additional performance gain when dealing with IO, as you can ignore the Byte > > Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward. > > What the heck is middle endian? ;^) The other two, being a Mac user > when I'm not at work, have pretty clear meanings. > > But this makes some sense for why things are -1 and not 1 or (as you > point out below) -0. False is "everything off" and True is "every > switch on". And 11111111 = -1 -- but it's not -1 in signed Integers, > which is confusing. That'd be 10000001, right? > > > IF you did have a 1 Bit signed integer type, if the value was not 0, it would > > be -1 (or -0, but that's a discussion for another day) > > Actually that makes sense and we can dispense with the new discussion! > ;^) That's part of my original wondering about why it works as it > does. 10000000 in a signed byte would be "negative 0000000". I've > done just enough assembly > (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a > decent handle on how the bits work. It would have made sense to me to > have "official True" be 10000000 (a quick rol to check) or 00000001 > (1=1), but 10000001 (signed -1) didn't make much sense at all. > > Now, again, 11111111 is -1 in unsigned bytes, right? That makes some > sense as True. > > Though admittedly I'm starting to wonder if I haven't got negative > signed byte expressions off in my head, as everyone seems to accept > 11111111 (realizing I'm simplifying everything using one byte instead > of 32 bit fun) as -1 *signed*. ??? > > > A Boolean evaluation of an expression is actually a double negative. > > If an expression does not evaluate to False(0), then it must be True. So all non > > zero values are True. > > That's been mentioned a few times, and immediately after posting it > occurred to me to check and see what CBool(1) gave me (True). But why > CInt(True) gave me -1 for "official True" was a mystery. I think the > "all bits True in the byte" makes the most sense. Whether that's -1 > in signed- or unsigned-land, I'll straighten out in my head later! > > Thanks everyone for the posts. Feel free to lambast my relatively > weak grasping of the situation! If I didn't have so many bad habits > already, the "Turn on Option Strict" post my be the best suggestion of > them all. > > Ruffin Bailey
I just miss using while(3) in C :(
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Agreed. I haven't investigated the actual implementation in dotNet or the
other various languages. This has become more about the mechanics of it all as opposed to the implementation. Although if one was to ask me to guess what the implementation would have
been, my guess would not have been +1. So I do find the actual implementation to be interesting.
In the end, I think Greg deserves the vote for the "best" answer. FALSE = 0 TRUE = !FALSE
But as it turns out, how you actually implement that can vary.
Gerald There are 10 kinds of people in the world. Those that understand Binary, and those that do not. (oldie but goodie, and appropriate here)
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in
message news:OX******** ******@TK2MSFTN GP12.phx.gbl... All of this is a bit superfluous really. I have discovered that the compiler stores a +1 for True on the stack for a boolean type 'True'
and 0 for a Boolean Type 'False'
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. As a side note, this is what makes the topic of -0 interesting. If you do some research, you will see that when using two's
complement, you get a couple of interesting exceptions to the rule that would seemingly
break things. But when they are resolved, they actually end up being what
you wanted in the first place. -0 and +128 would be of significant note. This is why a signed byte ranges from -128 to +127. And not +- 127 or +- 128.
Gerald
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:eq******** ******@TK2MSFTN GP10.phx.gbl... > Ruffin, > > Middle Endian is when you fiddle with the byte ordering in the Word. > 1-2-3-4 Big Endian > 4-3-2-1 Little Endian > 3-4-1-2 / 2-1-3-4 Middle Endian > > Take a look at: > http://en.wikipedia.org/wiki/Endianness > > This works best on 16Bit computers living in the 32Bit world. > In fact, some IO in Windows still works this way. > > Your confusion on the representation of Bits and why -1=11111111 and
not > 10000001 is because you are thinking as a human :) > Binary math is simplified if you use "Two's Complement"
representation of the > binary for negative numbers. > That is how computers like to do it. > This would make the representation backwards from what you would
think. > Basically, take a positive representation, flip the bits, then add
1. > Take the value +1 = 0000001 > Flip the bits to make negative = 1111110 > Add 1 = 11111111 > > So 11111111 = -1 in a Signed Byte > In an Unsigned Byte, it would be 255 > > Hope this helps to clear things up a little. > > Gerald > > > "Ruffin Bailey" <ka****@mailina tor.com> wrote in message > news:fd******** *************** ***@posting.goo gle.com... > > "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message > news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. > > > Additionally, by storing the Boolean value as all 1's or all
0's, you get an > > > additional performance gain when dealing with IO, as you can
ignore the Byte > > > Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward. > > > > What the heck is middle endian? ;^) The other two, being a Mac
user > > when I'm not at work, have pretty clear meanings. > > > > But this makes some sense for why things are -1 and not 1 or (as
you > > point out below) -0. False is "everything off" and True is "every > > switch on". And 11111111 = -1 -- but it's not -1 in signed
Integers, > > which is confusing. That'd be 10000001, right? > > > > > IF you did have a 1 Bit signed integer type, if the value was
not 0, it > would > > > be -1 (or -0, but that's a discussion for another day) > > > > Actually that makes sense and we can dispense with the new
discussion! > > ;^) That's part of my original wondering about why it works as it > > does. 10000000 in a signed byte would be "negative 0000000".
I've > > done just enough assembly > > (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a > > decent handle on how the bits work. It would have made sense to
me to > > have "official True" be 10000000 (a quick rol to check) or
00000001 > > (1=1), but 10000001 (signed -1) didn't make much sense at all. > > > > Now, again, 11111111 is -1 in unsigned bytes, right? That makes
some > > sense as True. > > > > Though admittedly I'm starting to wonder if I haven't got negative > > signed byte expressions off in my head, as everyone seems to
accept > > 11111111 (realizing I'm simplifying everything using one byte
instead > > of 32 bit fun) as -1 *signed*. ??? > > > > > A Boolean evaluation of an expression is actually a double
negative. > > > If an expression does not evaluate to False(0), then it must be True. So all > non > > > zero values are True. > > > > That's been mentioned a few times, and immediately after posting
it > > occurred to me to check and see what CBool(1) gave me (True). But
why > > CInt(True) gave me -1 for "official True" was a mystery. I think
the > > "all bits True in the byte" makes the most sense. Whether
that's -1 > > in signed- or unsigned-land, I'll straighten out in my head later! > > > > Thanks everyone for the posts. Feel free to lambast my relatively > > weak grasping of the situation! If I didn't have so many bad
habits > > already, the "Turn on Option Strict" post my be the best
suggestion of > > them all. > > > > Ruffin Bailey > >
Like you, my 'C' days are well behind me ( probably for quite a few years ),
but I did used to have fun with it. My first program was to write a Star
Trek simulation ( text based ).
Ahh where did all those years go. ?
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Greg Young" <gr********@pla netbeach.com> wrote in message
news:e1******** *****@tk2msftng p13.phx.gbl... I just miss using while(3) in C :(
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Agreed. I haven't investigated the actual implementation in dotNet or
the other various languages. This has become more about the mechanics of it all as opposed to the implementation. Although if one was to ask me to guess what the implementation would
have been, my guess would not have been +1. So I do find the actual implementation to be interesting.
In the end, I think Greg deserves the vote for the "best" answer. FALSE = 0 TRUE = !FALSE
But as it turns out, how you actually implement that can vary.
Gerald There are 10 kinds of people in the world. Those that understand Binary, and those that do not. (oldie but goodie, and appropriate here)
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message news:OX******** ******@TK2MSFTN GP12.phx.gbl... All of this is a bit superfluous really. I have discovered that the compiler stores a +1 for True on the stack for a boolean type 'True' and 0 for a Boolean Type 'False'
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. > As a side note, this is what makes the topic of -0 interesting. > If you do some research, you will see that when using two's complement, you get > a couple of interesting exceptions to the rule that would seemingly break > things. But when they are resolved, they actually end up being what you wanted > in the first place. > -0 and +128 would be of significant note. > This is why a signed byte ranges from -128 to +127. > And not +- 127 or +- 128. > > Gerald > > "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message > news:eq******** ******@TK2MSFTN GP10.phx.gbl... > > Ruffin, > > > > Middle Endian is when you fiddle with the byte ordering in the
Word. > > 1-2-3-4 Big Endian > > 4-3-2-1 Little Endian > > 3-4-1-2 / 2-1-3-4 Middle Endian > > > > Take a look at: > > http://en.wikipedia.org/wiki/Endianness > > > > This works best on 16Bit computers living in the 32Bit world. > > In fact, some IO in Windows still works this way. > > > > Your confusion on the representation of Bits and why -1=11111111
and not > > 10000001 is because you are thinking as a human :) > > Binary math is simplified if you use "Two's Complement" representation of the > > binary for negative numbers. > > That is how computers like to do it. > > This would make the representation backwards from what you would think. > > Basically, take a positive representation, flip the bits, then add 1. > > Take the value +1 = 0000001 > > Flip the bits to make negative = 1111110 > > Add 1 = 11111111 > > > > So 11111111 = -1 in a Signed Byte > > In an Unsigned Byte, it would be 255 > > > > Hope this helps to clear things up a little. > > > > Gerald > > > > > > "Ruffin Bailey" <ka****@mailina tor.com> wrote in message > > news:fd******** *************** ***@posting.goo gle.com... > > > "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message > > news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. > > > > Additionally, by storing the Boolean value as all 1's or all 0's, you get > an > > > > additional performance gain when dealing with IO, as you can ignore the > Byte > > > > Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward. > > > > > > What the heck is middle endian? ;^) The other two, being a Mac user > > > when I'm not at work, have pretty clear meanings. > > > > > > But this makes some sense for why things are -1 and not 1 or (as you > > > point out below) -0. False is "everything off" and True is
"every > > > switch on". And 11111111 = -1 -- but it's not -1 in signed Integers, > > > which is confusing. That'd be 10000001, right? > > > > > > > IF you did have a 1 Bit signed integer type, if the value was not 0, it > > would > > > > be -1 (or -0, but that's a discussion for another day) > > > > > > Actually that makes sense and we can dispense with the new discussion! > > > ;^) That's part of my original wondering about why it works as
it > > > does. 10000000 in a signed byte would be "negative 0000000". I've > > > done just enough assembly > > > (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have
a > > > decent handle on how the bits work. It would have made sense to me to > > > have "official True" be 10000000 (a quick rol to check) or 00000001 > > > (1=1), but 10000001 (signed -1) didn't make much sense at all. > > > > > > Now, again, 11111111 is -1 in unsigned bytes, right? That makes some > > > sense as True. > > > > > > Though admittedly I'm starting to wonder if I haven't got
negative > > > signed byte expressions off in my head, as everyone seems to accept > > > 11111111 (realizing I'm simplifying everything using one byte instead > > > of 32 bit fun) as -1 *signed*. ??? > > > > > > > A Boolean evaluation of an expression is actually a double negative. > > > > If an expression does not evaluate to False(0), then it must
be True. So > all > > non > > > > zero values are True. > > > > > > That's been mentioned a few times, and immediately after posting it > > > occurred to me to check and see what CBool(1) gave me (True).
But why > > > CInt(True) gave me -1 for "official True" was a mystery. I
think the > > > "all bits True in the byte" makes the most sense. Whether that's -1 > > > in signed- or unsigned-land, I'll straighten out in my head
later! > > > > > > Thanks everyone for the posts. Feel free to lambast my
relatively > > > weak grasping of the situation! If I didn't have so many bad
habits > > > already, the "Turn on Option Strict" post my be the best suggestion of > > > them all. > > > > > > Ruffin Bailey > > > > > >
Hey did u ever write assember for the BBC home computer ? Remember the 6502
processor with three registers, one accumulator and two addressing
registers. ?
I was only about 17 at the time, but it was big time fun. Those were the
days, no IDE, just peices of paper to do your design and fine mind !
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Agreed. I haven't investigated the actual implementation in dotNet or the
other various languages. This has become more about the mechanics of it all as opposed to the implementation. Although if one was to ask me to guess what the implementation would have
been, my guess would not have been +1. So I do find the actual implementation to be interesting.
In the end, I think Greg deserves the vote for the "best" answer. FALSE = 0 TRUE = !FALSE
But as it turns out, how you actually implement that can vary.
Gerald There are 10 kinds of people in the world. Those that understand Binary, and those that do not. (oldie but goodie, and appropriate here)
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in
message news:OX******** ******@TK2MSFTN GP12.phx.gbl... All of this is a bit superfluous really. I have discovered that the compiler stores a +1 for True on the stack for a boolean type 'True'
and 0 for a Boolean Type 'False'
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. As a side note, this is what makes the topic of -0 interesting. If you do some research, you will see that when using two's
complement, you get a couple of interesting exceptions to the rule that would seemingly
break things. But when they are resolved, they actually end up being what
you wanted in the first place. -0 and +128 would be of significant note. This is why a signed byte ranges from -128 to +127. And not +- 127 or +- 128.
Gerald
"Cablewizar d" <Ca*********@Ya hoo.com> wrote in message news:eq******** ******@TK2MSFTN GP10.phx.gbl... > Ruffin, > > Middle Endian is when you fiddle with the byte ordering in the Word. > 1-2-3-4 Big Endian > 4-3-2-1 Little Endian > 3-4-1-2 / 2-1-3-4 Middle Endian > > Take a look at: > http://en.wikipedia.org/wiki/Endianness > > This works best on 16Bit computers living in the 32Bit world. > In fact, some IO in Windows still works this way. > > Your confusion on the representation of Bits and why -1=11111111 and
not > 10000001 is because you are thinking as a human :) > Binary math is simplified if you use "Two's Complement"
representation of the > binary for negative numbers. > That is how computers like to do it. > This would make the representation backwards from what you would
think. > Basically, take a positive representation, flip the bits, then add
1. > Take the value +1 = 0000001 > Flip the bits to make negative = 1111110 > Add 1 = 11111111 > > So 11111111 = -1 in a Signed Byte > In an Unsigned Byte, it would be 255 > > Hope this helps to clear things up a little. > > Gerald > > > "Ruffin Bailey" <ka****@mailina tor.com> wrote in message > news:fd******** *************** ***@posting.goo gle.com... > > "Cablewizar d" <Ca*********@Ya hoo.com> wrote in message > news:<#T******* *******@TK2MSFT NGP12.phx.gbl>. .. > > > Additionally, by storing the Boolean value as all 1's or all
0's, you get an > > > additional performance gain when dealing with IO, as you can
ignore the Byte > > > Ordering (Little/Middle/Big Endean). 1111 = 1111 forward or backward. > > > > What the heck is middle endian? ;^) The other two, being a Mac
user > > when I'm not at work, have pretty clear meanings. > > > > But this makes some sense for why things are -1 and not 1 or (as
you > > point out below) -0. False is "everything off" and True is "every > > switch on". And 11111111 = -1 -- but it's not -1 in signed
Integers, > > which is confusing. That'd be 10000001, right? > > > > > IF you did have a 1 Bit signed integer type, if the value was
not 0, it > would > > > be -1 (or -0, but that's a discussion for another day) > > > > Actually that makes sense and we can dispense with the new
discussion! > > ;^) That's part of my original wondering about why it works as it > > does. 10000000 in a signed byte would be "negative 0000000".
I've > > done just enough assembly > > (http://mywebpages.comcast.net/rufbo1/mactari/mact.html) to have a > > decent handle on how the bits work. It would have made sense to
me to > > have "official True" be 10000000 (a quick rol to check) or
00000001 > > (1=1), but 10000001 (signed -1) didn't make much sense at all. > > > > Now, again, 11111111 is -1 in unsigned bytes, right? That makes
some > > sense as True. > > > > Though admittedly I'm starting to wonder if I haven't got negative > > signed byte expressions off in my head, as everyone seems to
accept > > 11111111 (realizing I'm simplifying everything using one byte
instead > > of 32 bit fun) as -1 *signed*. ??? > > > > > A Boolean evaluation of an expression is actually a double
negative. > > > If an expression does not evaluate to False(0), then it must be True. So all > non > > > zero values are True. > > > > That's been mentioned a few times, and immediately after posting
it > > occurred to me to check and see what CBool(1) gave me (True). But
why > > CInt(True) gave me -1 for "official True" was a mystery. I think
the > > "all bits True in the byte" makes the most sense. Whether
that's -1 > > in signed- or unsigned-land, I'll straighten out in my head later! > > > > Thanks everyone for the posts. Feel free to lambast my relatively > > weak grasping of the situation! If I didn't have so many bad
habits > > already, the "Turn on Option Strict" post my be the best
suggestion of > > them all. > > > > Ruffin Bailey > >
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |