boolean

overriding bool() for custom class

All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =) I've tried this: class test: def __bool__(self): return False myInst = test() print bool(myInst) #prints "True" print myInst.__bool__() #prints "False" Any sugg...

Boolean bitmap operation in .NET?

Hello, I have two 8bpp bitmaps. I want to do a bitwise AND of one to the other, but I don't see any obvious way to do this in .NET. Is it possible to do this without using non-.NET methods? Thanks! ...

boolean text search in python

i'm looking for an existing module(s) which enabled me to write basic boolean queries for matching and searching texts, WITHOUT writing my own parser etc. for example, president AND (ronald OR (george NOT bush)) would match TRUE against "the president ronald ragen" "the president ronald ragen and bush" "max bush was not a president" ...

Is there a way to get `true`/`false` values from a Boolean in PHP

When I cast to Boolean (using (bool)), is there a built in way to get PHP to actually return the constants true or false. At the moment I'm getting 1 or blank, which evaluate to true and false respectively. I want the value returned for clearer semantics. However, if I can't get it, I'll just settle with 1 and blank. Update I've reali...

What is the preferred order for operands in boolean expressions?

Is there any benefit to structuring boolean expressions like: if (0 < x) { ... } instead of if (x > 0) { ... } I have always used the second way, always putting the variable as the first operand and using whatever boolean operator makes sense, but lately I have read code that uses the first method, and after getting over the initia...

boolean string formatting in Python?

I see I can't do: "%b %b" % (True, False) in Python. I guessed %b for b(oolean). Is there something like this? ...

MySQL question, unexpected behaviour 'in boolean mode'

I use the following call for getting information from a database: select * from submissions where match( description ) against ('+snowboard' in boolean mode ) and (!disabled or disabled='n') order by datelisted desc limit 30 Which means everything with ‘snowboard' in the description is found. Now here’s the problem: select ...

Conditional logic on SQL aliases

I've got an SQL query that pieces together historic price information. It's not particularly clean and could probably be optimized a great deal. One reason for this is that I use a subquery to grab the 'previous' price value via a subquery and assign it to the alias 'last_value'. Ideally, I'd like to be able to use this alias in the quer...

In Java, what are the boolean "order of operations"?

Let's take a simple example of an object "Cat". I want to be sure the "not null" cat is either orange or grey. if(cat != null && cat.getColor() == "orange" || cat.getColor() == "grey") { //do stuff } I believe AND comes first, then the OR. I'm kinda fuzzy though, so here are my questions: 1) Can someone walk me through this state...

ICollectionView.SortDescriptions does not work for boolean

Hi ! myListBox.Items.SortDescriptions.Add( new SortDescription("BoolProperty", ListSortDirection.Descending)); This sorting works only for string properties of the underlying project. Not with boolean? Is there a reason for that ? Thanks ! UPDATE: Yep, your example really works. But what's wrong on my example ? public clas...

Boolean and Math Expression Parser

Hello, I am writing an application that allows a user to enter a boolean expression. I need the ability to evaluate the entered boolean expression at runtime and am looking for both a parser and a expressoin validator. Parser The parser needs to take a boolean expression as a string and return true/false. Example: string expression...

In GCC-style extended inline asm, is it possible to output a "virtualized" boolean value, e.g. the carry flag?

If I have the following C++ code to compare two 128-bit unsigned integers, with inline amd-64 asm: struct uint128_t { uint64_t lo, hi; }; inline bool operator< (const uint128_t &a, const uint128_t &b) { uint64_t temp; bool result; __asm__( "cmpq %3, %2;" "sbbq %4, %1;" "setc %0;" : // outp...

Primitive Boolean size in C#

How are boolean variables in C# stored in memory? That is, are they stored as a byte and the other 7 bits are wasted, or, in the case of arrays, are they grouped into 1-byte blocks of booleans? This answers the same question regarding Java (http://stackoverflow.com/questions/1907318/java-boolean-primitive-type-size). Are Java and C# the...

Why am I getting System.FormatException: String was not recognized as a valid Boolean on a fraction of our customers machines?

Hello, Our c#.net software connects to an online app to deal with accounts and a shop. It does this using HttpWebRequest and HttpWebResponse. An example of this interaction, and one area where the exception in the title has come from is: var request = HttpWebRequest.Create(onlineApp + string.Format("isvalid.ashx?username={0}&password=...

simple boolean question

What am I doing wrong here? I am wanting to display integers from 1-100 who are divisible by either 6 or 7. That's done and working. The next step is to not display any that are divisible by both...that isn't working in my loop (those integers are still displaying) for (int i = 1; i < 100; i++) if (i % 6 == 0 || i % 7 == 0 && i %...

Java: for loop, incompatible types

I'm trying to run this for loop; for (int col= 0; grid[0].length; col++) However every time I try to compile I get an error stating 'incompatible types - found int but expected boolean' I can't work out what I'm doing wrong! ...

java: looping on the two boolean values (false, true)

This is a stylistic question. I want to loop twice with a variable on which is set to false, then to true. Which of these is clearer: A) for (final boolean on : new boolean[] { false, true} ) { doStuffBasedOnABooleanFlag(on); } B) for (int i = 0; i < 2; ++i) { final boolean on = (i == 1); doStuffBasedOnABooleanFlag(on); }...

Checking element values in a Boolean array - C#

I'm writing some error checking and trying to make use of an boolean array to store true or false in the elements and then my final condition parses through the stored elements to determine if its all true in visual studio 2008. Theres probably a easier way to do the error checking, but might as well learn how to utilize an array. Here's...

Why doesn't MySQL define a boolean data type?

MySQL doesn't define a distinct boolean data type, opting instead to make BOOL and BOOLEAN aliases for TINYINT(1). Why is this so? ...

What is the preferred way to write boolean expressions in Java

I have always written my boolean expressions like this: if (!isValid) { // code } But my new employer insists on the following style: if (false == isValid) { // code } Is one style preferred, or standard? ...