Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to "true" and 0 turns to "false"? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I'm a pedant. :)
...
I was wondering if there is a better way to cope with MS-Access' inability to handle NULL for boolean-values other than change the column-data-type to integer.
...
I have a co-worker that maintains that TRUE used to be defined as 0 and all other values were FALSE. I could swear that every language I've worked with, if you could even get a value for a boolean, that the value for FALSE is 0. Did TRUE used to be 0? If so, when did we switch?
...
Can someone explain what exactly the string "0 but true" means in Perl? As far as I understand, it equals zero in an integer comparison, but evaluates to true when used as a boolean. Is this correct? Is this a normal behavior of the language or is this a special string treated as a special case in the interpreter?
...
What is the difference between Bool and Boolean types in C#?
...
A colleague of mine states that booleans as method arguments are not acceptable. They shall be replaced by enumerations. At first I did not see any benefit, but he gave me an example.
What's easier to understand?
file.writeData( data, true );
Or
enum WriteMode {
Append,
Overwrite
};
file.writeData( data, Append );
Now I got i...
When using IF statements in Python, you have to do the following to make the "cascade" work correctly.
if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
Is there a way to make Python accept multiple values when checking for "equals to"? For example,
if job == "mec...
What is the best way to convert an int or null to boolean value in an SQL query, such that:
Any non-null value is TRUE in the results
Any null value is FALSE in the results
...
Hi,
This is a silly question but why does a Boolean take up 4 bytes and a char take up 2 in the .NET framework?
It makes me wonder if I should start using chars like a boolean to save memory in large apps.
...
[This question is related to but not the same as this one.]
If I try to use values of certain types as boolean expressions, I get a warning. Rather than suppress the warning, I sometimes use the ternary operator (?:) to convert to a bool. Using two not operators (!!) seems to do the same thing.
Here's what I mean:
typedef long T; ...
I have a multi-threaded C++ app which does 3D rendering with the OpenSceneGraph library. I'm planning to kick off OSG's render loop as a separate thread using boost::threads, passing a data structure containing shared state in to the thread. I'm trying to avoid anything too heavyweight (like mutexes) for synchronization, as the render lo...
Is there a better way to negate a boolean in Java than a simple if-else?
if (theBoolean) theBoolean = false; else theBoolean = true;
...
I have essentially a survey that is shown, and people answer questions a lot like a test,
and there are different paths, it is pretty easy so far, but i wanted to make it more dynamic, so that i can have a generic rule that is for the test with all the paths, to make the evaluator easier to work with currently i just allow AND's, and ea...
Hi all.
I want to do a select in MySql that combines several columns... something like this pseudocode:
select payment1_paid and payment2_paid as paid_in_full from denormalized_payments where payment1_type = 'check';
Edit: payment1_paid and payment2_paid are booleans.
I can't use any other language for this particular problem than ...
I just came onto a project with a pretty huge code base.
I'm mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.
if (!!variable && (!!api.lookup("some-string"))) {
do_some_stuff();
}
I know these guys are intelligent programmers, it's obvious they aren't doing this by acci...
I'm working on an application developed by another mob and am confounded by the use of a char field instead of bit for all the boolean columns in the database. It uses "Y" for true and "N" for false (these have to be uppercase). The type name itself is then aliased with some obscure name like ybln.
This is very annoying to work with for...
An XML attribute declared as xs:boolean can acceptable be "true", "false", "0" or "1". However, in .NET, Boolean.Parse() will only accept "true" or "false". If it sees a "0" or "1", it throws a "Bad Format" exception.
So, given that, what's the best way to parse such a value into a Boolean?
(Unfortunately, I'm limited to .NET 2.0 solu...
Am I safe in casting a C++ bool to a Windows API BOOL via this construct
bool mybool = true;
BOOL apiboolean = mybool ? TRUE : FALSE;
I'd assume this is a yes because I don't see any obvious problems but I wanted to take a moment to ask only because this may be more subtle than it appears.
Thanks to Dima for (gently) pointing out my...
I'm reading The C++ Programming Language. In it Stroustrup states that sizeOf(chr) is always 1 and 1 <= sizeOf(bln). The specifics depend on the implementation. Why would such a simple value as a boolean take the same space as a char?
...
I'm someone who writes code just for fun and hasn't really delved into it in either an academic or professional setting, so stuff like this really escapes me. I was reading an article about JavaScript, which apparently supports bitwise operations. I keep seeing this mentioned in places and I've tried reading about to figure out what exac...