boolean

Boolean Marshalling with LayoutKind.Explicit, Is this broken or failing as designed?

First of all the Boolean type is said to have a default marshal type of a four-byte value. So the following code works: struct A { public bool bValue1; public int iValue2; } struct B { public int iValue1; public bool bValue2; } public static void Main() { in...

Effect of a Bitwise Operator on a Boolean in Java

The bitwise operators are supposed to travel the variables and operate on the bit by bit. In the case of integers, longs, chars this makes sense. These variables can contain the full range of values enforced by their size. In the case of booleans, however, a boolean can contain only two values. 1 = true or 0 = false. But the size ...

Should I use 0/1 or True/False boolean?

0/1 can be flexible and can add options such as "2, 3, 4" in the future. Does TinyINT in MySQL take up more space than boolean? Personally, I use 0 and 1 for everything. You can answer this question in the context of regular programming (or mysql, whichever you like) ...

Boolean Expression Evaluation in Java

Hey everyone, Is there a relatively simpler (when compared with writing a parser) way to evaluate boolean expressions in Java? I do not want to use the JEP library. I have a String expression something like: (x > 4 || x < 8 && p > 6) [ I will replace the variables with values. Is there a way by which I can evaluate this expression? The ...

Pass a Boolean Ada type in Interfaces.C

I would like to now how to pass a standard Boolean Type in Ada through the Interfaces.C package in order to call a DLL function. The Interfaces.C package does not contain the Ada Boolean type since the boolean type does not exist in ANSI C. I have a DLL function written in C++ whose exported function prototype has an argument of type Boo...

Boolean in Python

Does Python actually contain a Boolean value? I know that you can do: checker = 1 if checker: #dostuff But I'm quite pedantic and enjoy seeing booleans in Java. For instance: Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuff } Is there such a thing as this in Python? I can't seem to find ...

Simple read vs write boolean variable performance comparison question

What should be the preferred way by programmers: 1) Only Write: SomeBoolean = True 2) Read but write only if necessary If Not SomeBoolean Then SomeBoolean = True ...

How do I convert a MySQL function result to tinyint(1)

Here's the problem. In MySQL's Connector/NET a TINYINT(1) field properly translates back and forth into a .NET bool value. If I select from a table with a TINYINT(1) column, everything is golden. However, when you use built-in MySQL v5.0 functions like: SELECT (3 BETWEEN 2 AND 4) AS oddly_not_boolean; The actual return type from the d...

ROR - My logic works, Boolean value doesn't post

Hello fellas, My logic tests an inventory supply; and the < operator functions fine. How do I assign boolean values to "instock"? (using POST) In this test, under both conditions the value remains unchanged and this sample code does not work. Also this code is placed in an html.erb file, is there a better place for this code? <% if @i...

How to check if String value is Boolean type in Java?

I did a little search on this but couldn't find anything useful. The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false. I tried these: String value = "false"; System.out.println("test1: " + Boolean.parseBoolean(value)); System.out.println("test2: " + B...

A Method that returns true if the Temperature objects represents a temp below freezing point (JAVA)

I'm trying to write a method named isLowerThanFreezing that returns true if the Temperature object represents a temperature below the freezing point for water (32.0 F, 0.0 C, or 273.15 K), and false otherwise. This method should include only one inequality (i.e, one comparison formed using <, <=, >, or >=), which can be accomplished by d...

Equivalence testing in Haskell

Hi A quick question that has been bugging me lately. Does Haskell perform all the equivalence test in a function that returns a booleanm, even if one returns a false value? eg: f a b = ((a+b) == 2) && ((a*b) == 2) If the first test returns false, will it perform the second test after the &&? Or is Haskell lazy enough to not do it and...

Boolean fields in MySQL Django Models?

At Django, a boolean field in MySQL is stored as a TINYINT. When I retrieve it, I get 0 or 1. Shouldn't I get False or True? Is there a way to achieve this behaviour? ...

Boolean expressions for a tagging system in SQL

Having this SQL tables for a tagging system: CREATE TABLE tags ( id SERIAL PRIMARY KEY, name VARCHAR(100) ); CREATE INDEX tags_name_idx ON tags(name); CREATE TABLE tagged_items ( tag_id INT, item_id INT ); CREATE INDEX tagged_items_tag_id_idx ON tagged_items(tag_id); CREATE INDEX tagged_items_item_id_idx ON tagged_items...

Windows: How big is a BOOL?

How big (in bits) is a Windows BOOL data type? Microsoft defines the BOOL data type as: BOOL Boolean variable (should be TRUE or FALSE). This type is declared in WinDef.h as follows: typedef int BOOL; Which converts my question into: How big (in bits) is an int data type? Edit: In before K&R. Edit 2: Somethi...

Attempt to insert nil

Seems like it should be easy to add a boolean to an NSMutableArray. Assume toDoArray is intialized as an NSMutableArray. The following: BOOL checkBoxState = NO; [toDoArray addObject:checkBoxState]; Generates the error "attempt to insert nil." What's the correct way to add a negative boolean to a mutable array? ...

int and boolean error

I have a method that generates and error that a int was expected but found boolean but when I switch it to a boolean it says the same error but reverse int and boolean. Here is my code: private void compileDeclaration(boolean isGlobal) { if (equals(theToken, "int")) { accept("int"); String ident = theTok...

php boolean TRUE / FALSE question?

i cant figure this out. if i type function myfunction(){ ...... if ... return TRUE; if ... return FALSE; } why cant i use it like this: $result = myfunction(); if ($result == TRUE) ... if ($result == FALSE) ... or do i have to use: $result = myfunction(); if ($result == 1) ... if ($result == 0) ... o...

Using a boolean variable in while statement

A newbie question. I have the following piece of Java code: import acm.program.*; import java.awt.Color; import acm.graphics.*; public class ufo extends GraphicsProgram{ private GRect ufo_ship; boolean hasNotLost; public void run (){ setup(); //places ufo_ship to initial position hasNotLost = ufo_ship.getY() ...

Erlang compound boolean expression

I am still finding my feet with erlang, and I read the documentation about using "and", "or" operators, but why is the following not evaluating? X = 15, Y = 20, X==15 and Y==20. I am expecting for a "true" in the terminal, but I get a "syntax error before ==". ...