Search Results

Search found 8776 results on 352 pages for 'boolean logic'.

Page 2/352 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • What is the logic behind this C Program?

    - by iamanimesh19
    Here is a small piece of program (14 lines of program) which counts the number of bits set in a number. Input-Output -- 0--0(0000000), 5--2(0000101), 7--3(0000111) int CountBits (unsigned int x) { static unsigned int mask[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF } ; int i ; int shift ; /* Number of positions to shift to right*/ for (i =0, shift =1; i < 5; i ++, shift *= 2) x = (x & mask[i ])+ ( ( x >> shift) & mask[i]); return x; } Can someone explain the algorithm used here/why this works?

    Read the article

  • Techniques to increase logic at programming

    - by u3050
    I am into programming since last 3 years. But I seems to be lost in it. I am not able to get good at it even though I code everyday. suppose I solve one problem, I will wander from solution to solution and implement some other solution. I cant focus much. I get many defects for the code I write. I afraid of code I dont know why if I dont finish it on time my boss will fire me etc. I enjoy coding but not all the time. How to increase patience? I always wonder how do I become the best coder like many exceptional programmers. I know this sounds subjective but I think this will help programmer community to get good at it especially for average like me or beginner programmers.

    Read the article

  • Logic or Algorithm to solve this problem [closed]

    - by jade
    I have two lists. List1 {a,b,c,d,e} and List2 {f,g,h,i,j} The relation between the two list is as follows a->g,a->h,h->c,h->d,d->i,d->j Now I have these two lists displayed. Based on the relation above on selecting element a from List1, List2 shows g,h. On selecting h from List2, in List1 c,d are shown in List1. On selecting d from List1 it shows i,j in List2. How to trace back to initial state by deselecting the elements in reverse order in which they have been selected?

    Read the article

  • JTable Boolean cell .. how to read it

    - by dimitar
    Hello guys, i have a table with a column that contains Boolean type. now when i try to run a program i have a problem: System.out.println(table.getColumnClass(5)); b= (Boolean)table.getValueAt(row, 5); It prints class java.lang.Boolean but also: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean and i even try with b= (Boolean)table.getValueAt(row, 5); b= Boolean.parseBoolean((String)table.getValueAt(row, 5)); b= table.getValueAt(row, 5); but those show error too. So how to fix this guys?

    Read the article

  • Calculating WPM given a variable stream of input

    - by Jaxo
    I'm creating an application that sits in the background and records all key presses (currently this is done and working; an event is fired every keydown/keyup). I want to offer a feature for the user that will show them their WPM over the entire session the program has been running for. This would be easy if I added a "Start" and "End" button to activate a timer, but I need to detect only when the user is typing continuously - ignoring all one-time keyboard shortcuts and breaks the user takes from typing. How in the world do I approach this? Is this even realistically & accurately possible?

    Read the article

  • iPhone: Save boolean into Core Data

    - by Nic Hubbard
    I have set up one of my core data attributes as a Boolean. Now, I need to set it, but XCode keeps telling me that it may not respond to setUseGPS. [ride setUseGPS: useGPS.on]; What is the method for setting a boolean in core data? All my other attributes are set this way, and they work great. So, not sure why a boolean does not work to be set this way?

    Read the article

  • Rails migration to add boolean column to Postgres on Heroku

    - by pmc255
    I'm trying to execute a simple Rails migration to add a boolean column to an existing table. Here's the add_column call: add_column :users, :soliciting, :boolean, :null => false, :default => false However, after the migration runs (successfully, with no errors), I don't see the new column. If I go into the console and list the columns on the User table, for example, with this command: >> User.columns.each { |c| puts "#{c.name} : #{c.type}" } All the other columns show up, but not the one I just added with the migration. What's even more strange is that looking up a random user object yields the Postgres version of booleans (Ruby strings) >> User.find(1).soliciting => "t" However, the existing boolean columns all show up with standard Ruby boolean values of true and false. What's going on here? Is the migration actually complete? Why doesn't the column show up, yet is accessible in the model objects?

    Read the article

  • test="" on a boolean always returns true

    - by user70448
    Why does <xsl:if test="<XPATH to boolean value here>"> ... </xsl:if> ALWAYS return true? Since boolean can be 0,1,"false" and "true" by definition, the ONLY way to test for a boolean value is to do string comparison against these. This can't be right.

    Read the article

  • JAXB - representing element as boolean?

    - by Marcus
    We have this XML: <Summary> <ValueA>xxx</ValueA> <ValueB/> </Summary> <ValueB/> will never have any attributes or inner elements. It's a boolean type element - it exists (true) or it doesn't (false). JAXB generated a Summary class with a String valueA member, which is good. But for ValueB, JAXB generated a ValueB inner class and a corresponding member: @XmlElement(name = "ValueB") protected Summary.ValueB valueB; But what I'd like is a boolean member and no inner class: @XmlElement(name = "ValueB") protected boolean valueB; How can you do this? I'm not looking to regenerate the classes, I'd like to just make the code change manually.

    Read the article

  • JAXB - representing an element as a boolean member?

    - by Marcus
    We have this XML: <Summary> <ValueA>xxx</ValueA> <ValueB/> </Summary> <ValueB/> will never have any attributes or inner elements. It's a boolean type element - it exists (true) or it doesn't (false). JAXB generated a Summary class with a String valueA member, which is good. But for ValueB, JAXB generated a ValueB inner class and a corresponding member: @XmlElement(name = "ValueB") protected Summary.ValueB valueB; But what I'd like is a boolean member and no inner class: @XmlElement(name = "ValueB") protected boolean valueB; How can you do this? I'm not looking to regenerate the classes, I'd like to just make the code change manually.

    Read the article

  • Rewrite probabilities as boolean algebra

    - by Magsol
    I'm given three binary random variables: X, Y, and Z. I'm also given the following: P(Z | X) P(Z | Y) P(X) P(Y) I'm then supposed to determine whether or not it is possible to find P(Z | Y, X). I've tried rewriting the solution in the form of Bayes' Theorem and have gotten nowhere. Given that these are boolean random variables, is it possible to rewrite the system in terms of boolean algebra? I understand that the conditionals can be mapped to boolean implications (x -> y, or !x + y), but I'm unsure how this would translate in terms of the overall problem I'm trying to solve. (yes, this is a homework problem, but here I'm much more interested in how to formally solve this problem than what the solution is...I also figured this question would be entirely too simple for MathOverflow)

    Read the article

  • Is there a boolean literal in SQLite?

    - by Benjamin Oakes
    I know about the boolean column type, but is there a boolean literal in SQLite? In other languages, this might be true or false. Obviously, I can use 0 and 1, but I tend to avoid so-called "magic numbers" where possible. From this list, it seems like it might exist in other SQL implementations, but not SQLite. (I'm using SQLite 3.6.10, for what it's worth.)

    Read the article

  • php string versus boolean speed test

    - by ae
    I'm looking at trying to optimise a particular function in a php app and foolishly assumed that a boolean lookup in a 'if' statement would be quicker than a string compare. But to check it I put together a short test (see below). To my surprise, the string lookup was quicker. Is there anything wrong with my test (I'm wired on too much coffee so I'm suspicious of my own code)? If not, I would be interested in any comments people have around string versus boolean lookups in php. The result for the first test (boolean lookup) was 0.168 The result for the second test (string lookup) was 0.005 <?php $how_many = 1000000; $counter1 = 0; $counter2 = 0; $abc = array('boolean_lookup'=>TRUE, 'string_lookup'=>'something_else'); $start = microtime(); for($i = 0; $i < $how_many; $i++) { if($abc['boolean_lookup']) { $counter1++; } } echo ($start - microtime()); echo '<hr>'; $start = microtime(); for($i = 0; $i < $how_many; $i++) { if($abc['string_lookup'] == 'something_else') { $counter2++; } } echo ($start - microtime());

    Read the article

  • boolean in java: what am I doing wrong?

    - by Cheesegraterr
    Hello, I am trying to make my boolean value work. I am new at programming java so I must be missing something simple. I am trying to make it so that if one of the tire pressures is below 35 or over 45 the system outputs "bad inflation" For class me must use a boolean which is what I tried. I cant figure out why this isnt working. No matter what I do the boolean is always true. Any tips? public class tirePressure { private static double getDoubleSystem1 () //Private routine to simply read a double in from the command line { String myInput1 = null; //Store the string that is read form the command line double numInput1 = 0; //Used to store the converted string into an double BufferedReader mySystem; //Buffer to store input mySystem = new BufferedReader (new InputStreamReader (System.in)); // creates a connection to system files or cmd try { myInput1 = mySystem.readLine (); //reads in data from console myInput1 = myInput1.trim (); //trim command cuts off unneccesary inputs } catch (IOException e) //checks for errors { System.out.println ("IOException: " + e); return -1; } numInput1 = Double.parseDouble (myInput1); //converts the string to an double return numInput1; //return double value to main program } static public void main (String[] args) { double TireFR; //double to store input from console double TireFL; double TireBR; double TireBL; boolean goodPressure; goodPressure = false; System.out.println ("Tire Pressure Checker"); System.out.println (" "); System.out.print ("Enter pressure of front left tire:"); TireFL = getDoubleSystem1 (); //read in an double from the user if (TireFL < 35 || TireFL > 45) { System.out.println ("Pressure out of range"); goodPressure = false; } System.out.print ("Enter pressure of front right tire:"); TireFR = getDoubleSystem1 (); //read in an double from the user if (TireFR < 35 || TireFR > 45) { System.out.println ("Pressure out of range"); goodPressure = false; } if (TireFL == TireFR) System.out.print (" "); else System.out.println ("Front tire pressures do not match"); System.out.println (" "); System.out.print ("Enter pressure of back left tire:"); TireBL = getDoubleSystem1 (); //read in an double from the user if (TireBL < 35 || TireBL > 45) { System.out.println ("Pressure out of range"); goodPressure = false; } System.out.print ("Enter pressure of back right tire:"); TireBR = getDoubleSystem1 (); //read in an double from the user if (TireBR < 35 || TireBR > 45) { System.out.println ("Pressure out of range"); goodPressure = false; } if (TireBL == TireBR) System.out.print (" "); else System.out.println ("Back tire pressures do not match"); if (goodPressure = true) System.out.println ("Inflation is OK."); else System.out.println ("Inflation is BAD."); System.out.println (goodPressure); } //mainmethod } // tirePressure Class

    Read the article

  • Why Use !boolean_variable Over boolean_variable == false

    - by ell
    A comment on this question: Calling A Method that returns a boolean value inside a conditional statement says that you should use !boolean instead of boolean == false when testing conditions. Why? To me boolean == false is much more natural in English and is more explicit. I apologise if this is just a matter of style, but I was wondering if there was some other reason for this preference of !boolean?

    Read the article

  • How do I parse boolean logic?

    - by d03boy
    I need to write a boolean logic parser which will translate the boolean logic language to a SQL WHERE clause. The order of the operands will always be in the correct order (with value on the right). Here is a relatively simple example. There could be nested parentheses and the use of NOT operators, etc. (CACOUNT=01 OR CACOUNT=02 OR CACOUNT=03 OR CACOUNT=05 OR CACOUNT=07 OR CACOUNT=09 OR CACOUNT=12 OR CACOUNT=13 OR CACOUNT=18) AND Q4=1 AND NAME=TIMOTHY Here is what the WHERE clause would resemble. WHERE ( EXISTS ( SELECT 1 FROM MyVerticalTable b WHERE b.Key=a.Key AND b.Key='CACOUNT' AND b.Value='01' ) )

    Read the article

  • Why .NET Boolean has TrueLiteral and TrueString?

    - by user309937
    Why in Boolean type there are two fields with the same value? internal const int True = 1; internal const int False = 0; internal const string TrueLiteral = "True"; internal const string FalseLiteral = "False"; and public static readonly string TrueString; public static readonly string FalseString; static Boolean() { TrueString = "True"; FalseString = "False"; } in reflector generated code, methods don't use those strings but: public string ToString(IFormatProvider provider) { if (!this) { return "False"; } return "True"; } would't it be better to use those const values?

    Read the article

  • cfgrid boolean column as Yes/No

    - by Gene R
    I have a boolean type column in an html cfgrid. The data is stored in the database as 1/0 and is returned from CF as such. I want the user to see Yes/No instead of 1/0. I tried QuerySetCell, and couldn't get it to work. The form is editable, when you double click the cell, the checkboxes show and it updates as it should. The only issue is the display. <cfform> <cfgrid name="blah" format="html" bind="mycfccall" selectmode="edit"> <cfgridcolumn name="bitCol" header="Is it" width="75" type="boolean"> </cfgrid> </cfform> Thanks in advance...

    Read the article

  • MySQL Full Text Search Boolean Mode Partial Match

    - by Rob
    I've found boolean mode of MySQL full text search useful, however there are a couple of things I can't seem to figure out how to achieve. For instance imagine I have a full text column containing the words "Steve's Javascript Tutorial - Part One". I would like to match this for each of the following searches: "tutorials", "javascript tutorials", "java", "java script", "script" Imagine that each of those searches is simply assigned to a variable in whatever language may be being used (I always use PHP). How could I modify this to make sure that Steve's article is returned on each of those searches? MATCH (article_title) AGAINST ('"+$variable+"*' IN BOOLEAN MODE)

    Read the article

  • C++ / Java: Toggle boolean statement?

    - by Martijn Courteaux
    Hi, Is there a short way to toggle a boolean? With integers we can do operations like this: int i = 4; i *= 4; // equals 16 /* Which is equivalent to */ i = i * 4; So is there also something for booleans (like the *= operator for ints)? In C++: bool booleanWithAVeryLongName = true; booleanWithAVeryLongName = !booleanWithAVeryLongName; // Can it shorter? booleanWithAVeryLongName !=; // Or something? In Java: boolean booleanWithAVeryLongName = true; booleanWithAVeryLongName = !booleanWithAVeryLongName; // Can it shorter? booleanWithAVeryLongName !=; // Or something?

    Read the article

  • Business Logic Layer Pattern on Rails? MVCL

    - by Fabiano PS
    That is a broad question, and I appreciate no short/dumb asnwers like: "Oh that is the model job, this quest is retarded (period)" PROBLEM Where I work at people created a system over 2 years for managing the manufacture process over demand in the most simplified still broad as possible, involving selling, buying, assemble, The system is coded over Ruby On Rails. The app has been changed lots of times and the result is a mess on callbacks (some are called several times), 200+ models, and fat controllers: Total bad. The QUESTION is, if there is a gem, or pattern designed to handle Rails large app logic? The logic whould be able to fully talk to models (whose only concern would be data format handling and validation) What I EXPECT is to reduce complexity from various controllers, and hard to track callbacks into files with the responsibility to handle a business operation logic. In some cases there is the need to wait for a response, in others, only validation of the input is enough and a bg process would take place. ie: -- Sell some products (need to wait the operation to finish) 1. Set a View able to get the products input 2. Controller gets the product list inputed by employee and call the logic Logic::ExecuteWithResponse('sell', 'products', :prods => @product_list_with_qtt, :when => @date, :employee => current_user() ) This Logic would handle buying order, assemble order, machine schedule, warehouse reservation, and others. Have in mind that a callback on SalesOrder is not enough, since it depends on where it is called (no field for that), depends on the class of the user, among other stuff not visible for the model, or in some cases it would take long for the model to process.

    Read the article

  • Thick models Vs. Business Logic, Where do you draw the distinction?

    - by TokenMacGuy
    Today I got into a heated debate with another developer at my organization about where and how to add methods to database mapped classes. We use sqlalchemy, and a major part of the existing code base in our database models is little more than a bag of mapped properties with a class name, a nearly mechanical translation from database tables to python objects. In the argument, my position was that that the primary value of using an ORM was that you can attach low level behaviors and algorithms to the mapped classes. Models are classes first, and secondarily persistent (they could be persistent using xml in a filesystem, you don't need to care). His view was that any behavior at all is "business logic", and necessarily belongs anywhere but in the persistent model, which are to be used for database persistence only. I certainly do think that there is a distinction between what is business logic, and should be separated, since it has some isolation from the lower level of how that gets implemented, and domain logic, which I believe is the abstraction provided by the model classes argued about in the previous paragraph, but I'm having a hard time putting my finger on what that is. I have a better sense of what might be the API (which, in our case, is HTTP "ReSTful"), in that users invoke the API with what they want to do, distinct from what they are allowed to do, and how it gets done. tl;dr: What kinds of things can or should go in a method in a mapped class when using an ORM, and what should be left out, to live in another layer of abstraction?

    Read the article

  • Boolean algebra simplification

    - by xbonez
    I need to reduce this boolean expression to its simplest form. Its given that the simplest form contains 3 terms and 7 literals. The expression is: x'yz + w'x'z + x'y + wxy + w'y'z We tried this in class, and even out recitation teacher could not figure it out. Any help would be appreciated.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >