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

前端 未结 5 457
臣服心动
臣服心动 2020-12-07 01:06

I know that a boolean value is 1 byte (8 bits long) But I would like to know is what is its binary representation. e.g. decimal => binary 4 => 100 (0000 0100)

5条回答
  •  悲&欢浪女
    2020-12-07 01:18

    Almost all languages/environments (not only .NET) implement true as equivalent to the integral value 1, and false equal to 0.1)

    However, there’s one important exception, namely VB6, which had true equal to –1. This made quite a few things difficult for the migration to .NET, because the loose type system of VB6 allowed to mix integers and booleans in the same expression, and 2 And True meant something else in VB6 than in VB.NET.


    1) Although many systems allow an implicit conversion of any numeric value unequal to 0 to true in a boolean context. Some (especially dynamic) languages even go further, and say that all objects except for special objects (e.g. None, empty array, the list goes on …) equal true.

提交回复
热议问题