Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 11th, 2006, 03:45 AM
Tyrone Chou
Guest
 
Posts: n/a
Default System.Boolean Question.

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
Default 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
Default 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.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles