What is the binary representation of a boolean value in c# -


i know boolean value 1 byte (8 bits long) know binary representation. e.g. decimal => binary 4 => 100 (0000 0100) 8 => 1000 (0000 1000) bool value => ???

bool built-in basic type in c#. underlying representation implementation detail.

the c# 4.0 language specification states in section 4.1.8:

the bool type represents boolean logical quantities. possible values of type bool true , false.

no standard conversions exist between bool , other types. in particular, bool type distinct , separate integral types, , bool value cannot used in place of integral value, , vice versa.

in c , c++ languages, 0 integral or floating-point value, or null pointer can converted boolean value false, , non-zero integral or floating-point value, or non-null pointer can converted boolean value true. in c#, such conversions accomplished explicitly comparing integral or floating-point value zero, or explicitly comparing object reference null.

if take 1 level deeper , see how corresponding type specied in common intermediate language (cil) see cli boolean type occupies 1 byte in memory. common language infrastructure (cli) specification says in partition iii, section 1.1.2:

a cli boolean type occupies 1 byte in memory. bit pattern of zeroes denotes value of false. bit pattern 1 or more bits set (analogous non-zero integer) denotes value of true.

however, specified on level , within c# should not have care; if future version of cli specification might change representation of boolean type, or if c# compiler decided map bool in c# different, c# code still have same semantics.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -