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
booltype represents boolean logical quantities. possible values of typebooltrue,false.no standard conversions exist between
bool, other types. in particular,booltype distinct , separate integral types, ,boolvalue 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 valuetrue. 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
Post a Comment