Connecting Tech Pros Worldwide Help | Site Map

System.Boolean Question.

  #1  
Old March 11th, 2006, 03:45 AM
Tyrone Chou
Guest
 
Posts: n/a
hello, everybody.

today, i read msdn like usual, suddenly i found variable with type of
System.Boolean should take up 2 Bytes. it surprised me a lot. why a
boolean value should take up 2 bytes? in my option, 1 bit should be ok:)


// code.
if (value == ASC(0)) {
return System.Boolean.FALSE;
} else {
return System.Boolean.TRUE;
}



Best Regards,

Tyrone Chou
3/10/2006
  #2  
Old March 11th, 2006, 06:05 AM
Daniel O'Connell [C# MVP]
Guest
 
Posts: n/a

re: System.Boolean Question.



"Tyrone Chou" <TyroneChou@MSN.Com> wrote in message
news:%23ME1hwLRGHA.4740@TK2MSFTNGP14.phx.gbl...[color=blue]
> hello, everybody.
>
> today, i read msdn like usual, suddenly i found variable with type of
> System.Boolean should take up 2 Bytes. it surprised me a lot. why a
> boolean value should take up 2 bytes? in my option, 1 bit should be ok:)
>[/color]

Well, a bit is out of the question. While it is nice space wise, accesing a
single bit is likely far more expensive than the additional few bits used to
store it. Space isn't everything.

Also, FWIW, I'm pretty sure the base boolean type is 4 bytes, because modern
procesors work with groups of 4 bytes better than they do with one.[color=blue]
>
> // code.
> if (value == ASC(0)) {
> return System.Boolean.FALSE;
> } else {
> return System.Boolean.TRUE;
> }[/color]

I don't see why this code is here. Did you have a question with regards to
it?


  #3  
Old March 11th, 2006, 10:45 AM
Mattias Sjögren
Guest
 
Posts: n/a

re: System.Boolean Question.


>today, i read msdn like usual, suddenly i found variable with type of[color=blue]
>System.Boolean should take up 2 Bytes. it surprised me a lot. why a
>boolean value should take up 2 bytes?[/color]

It doesn't, it takes one byte (the smallest size you can address). You
can check that yourself with sizeof(bool). Any MSND topics that says
otherwise are wrong. If you want to store a lot of boolean values with
just a single bit each, use a BitArray.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract class variables question tshad answers 20 November 20th, 2007 10:35 AM
String was not recognized as a valid Boolean dba123 answers 10 April 25th, 2006 05:25 PM
extending system.boolean ECathell answers 0 November 23rd, 2005 04:14 AM
Ask a Language Designer: boolean: C# vs. Xml Metro Sauper answers 8 November 15th, 2005 02:06 PM