Science Fair Projects Ideas - Boolean datatype

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Boolean datatype

(Redirected from Bool)

In computer science, the boolean datatype, sometimes called the logical datatype is a primitive datatype having two values, true and false.

This datatype is supported by boolean operations such as and (AND, &&), or (OR, ||), exclusive or/not equivalent (xor, NEQV), equal (=, ==) and not (NOT, !) which correspond to the operations of Boolean algebra.

Contents

Fortran

The LOGICAL keyword and associated operations .NOT., .AND., .OR., etc. were introduced in the 1950s, before Fortran was standardized.

Algol

Algol 60 had a boolean datatype and associated operations, defined in the Algol 60 report. This was abbreviated to bool in ALGOL 68.

C and C++

In the C programming language, there is no boolean type provided (true for ANSI C, but not for C99 C), but true/false values are determined by comparing a value to zero. For instance, the C code

if (my_variable) {
  printf("True!\n");
} else {
  printf("False!\n");
}

does the exact same thing as

if (my_variable != 0) {
  printf("True!\n");
} else {
  printf("False!\n");
}

This is straightforward for integer datatypes; because floating-point values are prone to rounding error, they should not be compared for equality. Traditionally, integers are used to contain one (or more) boolean variables, one for each bit of the integer.

While it is not necessary to name the true and false values in order to test variables for truth or falsehood, it is necessary to do so in order to assign values to them. (It's still possible to do so using the numbers zero and one, but this is clunky.) The enum keyword allows for naming elements:

typedef enum _boolean { FALSE, TRUE } boolean;
...
boolean b;

However, it is seldom used. Rather, simple integers are used along with the following preprocessor macros.

#define FALSE 0
#define TRUE 1
...
int f = FALSE;

The C++ programming language introduced the bool, true and false keywords, adding a native datatype to support boolean data.

Perl

In the Perl programming language, there is no distinction between numbers, strings and other non-aggregate data types. (They are all called "scalar".) Aggregate types with at least one element, non-empty strings (with the exception of "0") and integers with a non-zero value are considered to be true. There are scalars such as 0.0 and 0E0 which are "zero but true". There are no built-in true or false constants in Perl.

Visual Basic

In the Visual Basic programming language, boolean values from comparisons can be stored in variables with the boolean data type, which is stored as a two-byte integer but can only have the values True and False. For example:

Dim isSmall As Boolean
isSmall = intMyNumber < 10 ' Expression evaluates to True or False
If isSmall Then
   MessageBox.Show("The number is small")
Endif
Dim hellFreezesOver As Boolean 'Boolean variables are initialized as False
hellFreezesOver = False 'Or you can use an assignment statement
Do Until hellFreezesOver
   Call CheckAndProcessUserInput()
Loop

Java

In the Java programming language, Boolean variables are represented by the type boolean, which is 1 byte long. No explicit or implicit casts to or from boolean are permitted, i.e.

int i = 5;
if (i) System.out.println("I is five");

Will produce errors. Code to ouput a boolean could be represented like this:

boolean myBool = (i==5);
System.out.println(myBool ? "I = 5" : "I != 5");
Last updated: 10-08-2005 08:13:35
10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice