Questions tagged [boolean]

A Boolean data type is a data type with only two possible values: true or false.

The Boolean data type represents the simple True or False values of Boolean algebra.

Though one bit is all that is necessary to store a boolean (the 1 = true, 0 = false), it is often advantageous (if unintuitively so) to use larger amounts of memory.

Some programming languages actually define a three-valued logic within their Boolean type.

In , the Boolean class is java.lang.Boolean, the object version of primitive type boolean, and questions may be related to either. Note that the java.lang.Boolean fields may hold null as well, as it's an Object.

11685 questions
391
votes
15 answers

What is the difference between bool and Boolean types in C#

What is the difference between bool and Boolean types in C#?
Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199
365
votes
16 answers

How to convert String object to Boolean Object?

How to convert String object to Boolean object?
Suresh
  • 38,717
  • 16
  • 62
  • 66
334
votes
11 answers

Is there any boolean type in Oracle databases?

Is there any Boolean type in Oracle databases, similar to the BIT datatype in Ms SQL Server?
Peder
  • 3,341
  • 2
  • 15
  • 3
323
votes
8 answers

Default value of 'boolean' and 'Boolean' in Java

What are the default values of boolean (primitive) and Boolean (primitive wrapper) in Java?
Makky
  • 17,117
  • 17
  • 63
  • 86
306
votes
6 answers

Strange definitions of TRUE and FALSE macros

I have seen the following macro definitions in a coding book. #define TRUE '/'/'/' #define FALSE '-'-'-' There was no explanation there. Please explain to me how these will work as TRUE and FALSE.
Keshava GN
  • 4,195
  • 2
  • 36
  • 47
301
votes
12 answers

Volatile boolean vs AtomicBoolean

What does AtomicBoolean do that a volatile boolean cannot achieve?
JeffV
  • 52,985
  • 32
  • 103
  • 124
301
votes
12 answers

Is bool a native C type?

I've noticed that the Linux kernel code uses bool, but I thought that bool was a C++ type. Is bool a standard C extension (e.g., ISO C90) or a GCC extension?
asussex
  • 3,051
  • 2
  • 16
  • 6
299
votes
11 answers

Returning a boolean from a Bash function

I want to write a bash function that check if a file has certain properties and returns true or false. Then I can use it in my scripts in the "if". But what should I return? function myfun(){ ... return 0; else return 1; fi;} then I use it like…
luca
  • 12,311
  • 15
  • 70
  • 103
293
votes
4 answers

Is False == 0 and True == 1 an implementation detail or is it guaranteed by the language?

Is it guaranteed that False == 0 and True == 1, in Python (assuming that they are not reassigned by the user)? For instance, is it in any way guaranteed that the following code will always produce the same results, whatever the version of Python…
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
291
votes
4 answers

Logical operators for Boolean indexing in Pandas

I'm working with a Boolean index in Pandas. The question is why the statement: a[(a['some_column']==some_number) & (a['some_other_column']==some_other_number)] works fine whereas a[(a['some_column']==some_number) and…
user2988577
  • 3,997
  • 7
  • 21
  • 21
291
votes
7 answers

How do I create a numpy array of all True or all False?

In Python, how do I create a numpy array of arbitrary shape filled with all True or all False?
Michael Currie
  • 13,721
  • 9
  • 42
  • 58
284
votes
15 answers

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: >>> "0" == false true >>> false == "0" true So why does the following print "ha"? >>> if ("0") console.log("ha") ha
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
284
votes
13 answers

How can I map True/False to 1/0 in a Pandas DataFrame?

I have a column in python pandas DataFrame that has boolean True/False values, but for further calculations I need 1/0 representation. Is there a quick pandas/numpy way to do that?
Simon Righley
  • 4,538
  • 6
  • 26
  • 33
274
votes
7 answers

Why does Boolean.ToString output "True" and not "true"

true.ToString() false.toString(); Output: True False Is there a valid reason for it being "True" and not "true"? It breaks when writing XML as XML's boolean type is lower case, and also isn't compatible with C#'s true/false (not sure about CLS…
Chris S
  • 64,770
  • 52
  • 221
  • 239
258
votes
8 answers

Boolean vs boolean in Java

There are discussions around Integer vs int in Java. The default value of the former is null while in the latter it's 0. How about Boolean vs boolean? A variable in my application can have 0/1 values. I would like to use boolean/Boolean and prefer…
Neel
  • 9,913
  • 16
  • 52
  • 74