tagged [boolean]

Using NOT operator in IF conditions

Using NOT operator in IF conditions Is it really a good practice to avoid using NOT operator in IF conditions in order to make your code better readable? I heard the `if (doSomething())` is better the...

19 Feb at 20:40

Declaring a boolean in JavaScript using just var

Declaring a boolean in JavaScript using just var If I declare a JavaScript boolean variable like this: And then initialize it with either `true` or `1`, is that safe? Or will initializing it with `1` ...

12 Jan at 05:36

Why would one use the |= operator on a boolean value in C#?

Why would one use the |= operator on a boolean value in C#? Example: We found this is some vendor written code and we're trying to figure out why they'd do this.

28 Mar at 16:6

Better way to convert an int to a boolean

Better way to convert an int to a boolean The input `int` value only consist out of 1 or 0. I can solve the problem by writing a `if else` statement. Isn't there a way to cast the `int` into a `boolea...

15 Jul at 12:50

Is True (In PHP)?

Is True (In PHP)? What to use better? ...or: Both work, both check that is set to 'true'. The second one also checks 's type. If we assume that holds value that's boolean, what option should I use?

24 Apr at 18:10

How to use boolean datatype in C?

How to use boolean datatype in C? I was just writing code in C and it turns out it doesn't have a boolean/bool datatype. Is there any C library which I can include to give me the ability to return a b...

11 Apr at 00:10

In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by itself?

In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by itself? The following shows that `"0"` is false in Javascript: So why does the following print `"ha"`?

13 Jul at 02:36

How to convert string to boolean php

How to convert string to boolean php How can I convert string to `boolean`? it returns, > boolean true but it should be `boolean false`.

20 Jan at 15:27

How do you deal with NULL values in columns of type boolean in MS Access?

How do you deal with NULL values in columns of type boolean in MS Access? I was wondering if there is a better way to cope with MS-Access' inability to handle NULL for boolean-values other than change...

24 Sep at 15:56

Nullable bool as tri-state variable in C#

Nullable bool as tri-state variable in C# Is there any merit to using a nullable bool to store a tri-state value? For example, `null == 1st state, false == 2nd state, true == 3rd state`? The overhead ...

16 Mar at 10:21

Is a bool read/write atomic in C#

Is a bool read/write atomic in C# Is accessing a field atomic in C#? In particular, do I need to put a lock around:

12 Sep at 16:19

in C# what does 'bool = bool != true' mean?

in C# what does 'bool = bool != true' mean? In my hunt for some help to a problem I was having I came across this: What exactly does this mean? Ive never seen it before, nb: the preceeding line was `...

6 Mar at 13:7

Changing bool values to opposite of the initial value

Changing bool values to opposite of the initial value This maybe sound strange to you but I'm too lazy to write everytime like isn't there is something like int++ or int-- to change bool value to oppo...

2 Aug at 13:37

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

What is the binary representation of a boolean value in c# 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...

26 Jul at 14:36

Check whether a String is not Null and not Empty

Check whether a String is not Null and not Empty How can I check whether a string is not `null` and not empty?

What is the difference between Convert.ToBoolean(string) and Boolean.Parse(string)?

What is the difference between Convert.ToBoolean(string) and Boolean.Parse(string)? What is the difference between the two methods `Convert.ToBoolean()` and `Boolean.Parse()`? Is there any reason to u...

2 Aug at 11:27

What is the use of Nullable<bool> type?

What is the use of Nullable type? a variable could hold true or false, while could be null as well. Why would we need a third value for bool ? If it is not , what ever it is, it is == Can you suggest ...

6 Feb at 16:7

How can I return a bool value from a plethora of nullable bools?

How can I return a bool value from a plethora of nullable bools? With this code: ...I'm stopped dead in my tracks with So how do

18 Dec at 22:6

Generate Random Boolean Probability

Generate Random Boolean Probability I only know how I can generate a random boolean value (true/false). The default probability is 50:50 But how can I generate a true false value with my own probabili...

1 Dec at 10:25

Is this the proper way to do boolean test in SQL?

Is this the proper way to do boolean test in SQL? Assume active is a "boolean field" (tiny int, with 0 or 1) In words, can the "NOT" operator be applied directly on the boolean field?

11 Mar at 21:4

PHP - Get bool to echo false when false

PHP - Get bool to echo false when false The following code doesn't print out anything: But the following code prints `1`: Is there a better way to print `0` or `false` when `$bool_val` is `false` than...

1 Feb at 22:33

Java check if boolean is null

Java check if boolean is null How do you check if a boolean is null or not? So if I know "hideInNav" is null. How do I stop it from further executing? Something like the below doesn't seem to work but...

1 Mar at 10:6

Fastest way to generate a random boolean

Fastest way to generate a random boolean So there is several ways of creating a random bool in C#: - `rand.Next(2) == 0`- `rand.NextDouble() > 0.5` Is there really a difference? If so, which one actua...

4 Oct at 21:31

Performance: assign boolean value always or check value first?

Performance: assign boolean value always or check value first? I'm sure it is negligible, but given that I want to assign `true` to a boolean field from within a method, does this choice make any diff...

3 Jan at 17:40

UpdateNonDefaults is ignoring boolean parameters set to false

UpdateNonDefaults is ignoring boolean parameters set to false I'm trying to update a record in my SQL server 2012 Express DB using UpdateNonDefaults. Boolean fields which are set to false are getting ...

19 Dec at 02:22