By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,257 Members | 2,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,257 IT Pros & Developers. It's quick & easy.

System.Boolean Question.

P: 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
Mar 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Tyrone Chou" <Ty********@MSN.Com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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:)

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.
// code.
if (value == ASC(0)) {
return System.Boolean.FALSE;
} else {
return System.Boolean.TRUE;
}


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

P: n/a
>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?


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.
Mar 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more C# / C Sharp Questions on Bytes