Boolean | vs Logical ||?

First of all, I know this won't work for bitwise |.
But, this code:
boolean a=false, b=true, c;
c = a|b; // c is now true
c = a||b; // c is now also true
Is it just a remnant from the C-style language, or what?
Are boolean | and logical || optimized differently?
Conditions in Java can only evaluate to boolean values, so things like this
if ((a == false) | (b == false))
works just as well as
if ((a == false) || (b == false))
I'd say it's bad style to use || for boolean (as in c=a||b;), but does it really matter?
-- Tino Didriksen, [email protected]

| is a bitwise OR that operates on integral types (char, short, int, long), and apparently, boolean.
|| is a boolean or logical OR that operates on boolean.
| evaluates to an integral values (I don't know if it's int or the larger of the operand types, or what).
A || B can short circuit because the truth of the entire statement is known if A is true.
x | y cannot, in general, short circuit, because it's a bitwise or--that is, you have to examine each bit. Now you COULD examine only those bits of y for which the corresponding x bit was 0, and then if x was all 1s, not examine y at all. However, Java doesn't work this way, AFAIK--it just operates on all values as the general case--examining both operands.
It's been put forth that the difference between | and || is that | doesn't short circuit and || does. I would say that's a side effect. The real fundamental difference is that | does bitwise operations on integral operands to produce an integral result, whereas || does a boolean operation on boolean operands to produce a boolean result.
The comparisons using true/false stem from the fact that, for | (and I assume &), boolean expressions (e.g. true/false) seem to be treated as single bit integral types. However, in the general case, boolean and integral types are not interchangeable in Java, and the issues of short circuit vs. not doesn't apply, since the two operators do different things and operate on different types.

Similar Messages

  • Strange mapping of Boolean from Logical to DB2 Relational model

    Hi guys,
    Using most recent version of Data Modeler (3.3.0.747) I notice strange behavior:
    Attribute, declared as Boolean in Logical model is engineered to a column, with type CHAR(1) in Relational Model, when "RDBMS Type" is Oracle, but when "RDBMS Type" is "DB2", column type is CHAR(254)
    Is this a bug or a feature?
    Is there any way, where I can control type mapping between logical and relational model?
    Well, I can just go and change CHAR(254) to CHAR(1) all over my Relational Model, but this is pretty frustrating.
    MfG,
    Stoyan Tsonev

    Hi Stoyan,
    Is there any way, where I can control type mapping between logical and relational model?In fact mapping is between logical data type and database native types - Tools>Types Administration.
    You need to change mapping for Boolean logical data type - check "size" check box and put value in text field to define default size. Default size will be used when there is no explicitly defined size in column/domain definition.
    Philip

  • How to get the values of the VO

    Hello,
    I have one requirement on page where it displaying the Party information.
    1)We have to add tow more column for the party extra information from attribute column (attribute8,attribute9)
    2)There column should displayed when the attribute contain the values
    I have created New VO by extending the orginal VO and substituted This VO.
    Added three more column for attribute8,9 and transient attribute display_flag (boolean)
    It displaying the extra column asexpected.
    Now we are facing the issue when we want built the logic for displaying this columns when attributes column have values.
    Can any body help me how to achieve the above .
    Regards,
    Charudutta Dalvi.

    Hello requirement is as below
    We want to display the two more columns in following table
    Party Number    Party Name    Fiscal Code Attrubute8   Attribute9
    Now we extended the VO and added three more attributes, two for Attrubute8  ,Attribute9 and one more attribute display_flag (boolean)
    Our logic is if Party have attributes value then these column should be displayed if not then thse column should not displayed.
    We created this logic at VoRowImplentation in getdisplay_flag,and for attribute 8 and 9
    //if attributes columns contain data then is should return true for display_flag attribute.
    if(getattrubute8()!=null and getattribute8()!=null)
         return true;
    else
         return false.
    Then we done personlisation for attribute8 and 9 ,render property set to SPEL {oa.Vo1.display_flag}
    Now the problem is when there are three record,first record does not have value for  attribute8 and 9, then display_flag is false.
    and other records have values hence display_flag is true. due first row have display_flag =false the entire column for attrubute 8, and 9 are not displayed.
    then How to achive the above requirement,
    Using CO extension ?  Can you give me psedocode.
    Thank you.

  • How can I have multiple inputs into the selector terminal of a case structure

    Hi everyone
    I have a question on how to wire multiple inputs in to the selector terminal of a case structure. 
    Currently, I have three switches, each switch determines different case. So if I switch the switch 1 is on, the numeric indicator will show 1. If the switch 2 is on, the numeric indicator will show 2, so on and so forth. However, the selector terminal will not allow me to wire multiply inputs into the case structure, I tried Bundle by Name, Bundle and Array to Cluster, but they did not work. I set the case structure with 3 cases, they are 1, 2 and 3.
    Could someone help me please. I have attach an image and the VI of the work I did so far.
    I have another question, is there a function which can toggle other switches to off when there is a switch has been toggled on.
    Thank you very much
    Tommy
    Attachments:
    Trial - Case Structure.vi ‏7 KB

    Tommy, attached find a cheeseball way of doing this that has given me a LOT of mileage over the years.  IT lends itself nicely to a couple of really good practices that NI recommend, but I have given you the bare-bones to "see under the hood".  
    The recommended practices:
    1. You can make this a nice tight sub-vi where you can put it into a core library of routines that you'll use over the years, even extending the logic to look only for changes, etc.
    2.  If you are thinking about Front Panel design considerations, you'll want to use arrays of controls where possible, as that's a nice neat way of containerizing your switch for both the FP and Block Diagram.
    Have fun.  I have TONS of these types of things, so feel free to PM me if you have any other needs.
    Wes
    Wes Ramm, Cyth UK
    CLD, CPLI
    Attachments:
    Boolean Switch Logic.vi ‏11 KB

  • Question on closing Front Panel references

    I'm manipulating controls on the Front Panel of my VI.  In doing this, I open a slew of references (to the VI, to the Front Panel, to its Panes, and to the objects on the Front Panel).  Normally, before exiting the VI, I carefully close them (in LIFO order, of course), but a question has arisen:
    I want to "export" a series of references to Boolean controls for use in succeeding VIs.  No problem, while enumerating the controls (see above), I simply identify the Boolean references and build them into an array that I pass out.  First question -- does anything "go wrong" if I also do a "Close Ref" in the main loop (after adding the reference to the array, of course)?  [At present, I'm only doing a Close Ref on the non-Booleans].  Logic says this should be OK, as the Close Ref is mainly doing "garbage collection", and I've done a "copy" operation in building my array, but to a persistent structure.
    Second question -- in my "cleanup" routine, I noticed I was "double-disposing" of the references, that is, I did a Close Ref on my array of Boolean References, but also was enumerating the entire Front Panel (as I did when I opened it) and disposing of the references that it found.  Again, this should be no problem, but (in principle) I'm doing a Close Ref on two references to the Boolean control.  It occurs to me that this is not really logical either -- I should be able to simply "abandon" the array of references -- although it takes up memory that can be "reclaimed" for other uses, the fact that it is an array of RefNums is a "so what" -- the contents of the array could have been a numeric or other "solid" data type.
    Does this make sense?  To summarize, what I'm trying to do is to "extract" some RefNums to Front Panel objects for later use.  In the "extraction" process, I must open (and create references to) multiple objects, including RefNums to my "objects of interest".  What I think I can (and should) do, once I've copied the RefNums I need, is to dispose (Close Ref) all of the RefNums that I opened during the extraction routine, and do something equivalent when I do the subsequent "cleanup" (which undoes any modifications I made as part of the extraction).
    Comments welcome.
    Bob Schor

    I usually store the ref. at the beginning of my program, in Functional Globals, and i close them when the program does not need them any more. 
    I think this is the right approach. And it is simple

  • Pulse Generator

    We are posting a question in regard to creating a pulse generator that would:
    * have Boolean logic output
    * yield Boolean “high” logical level for ~ 0.2 ms at the repetition rate ~ 10 Hz
    * keep Boolean “low” logical level after generating the Boolean “high” 0.2 ms pulse
    * As an option, it would be great to adjust the pulse duration in a range 0.2-1000 ms, and adjust the rep. rate in a range 100 – 1 Hz.     
    We would then like to use the outputted logical waveform to modulate (turn on/off) a particular pin on an external board connected to PC via USB interface.
    We were thinking of using the Basic Function Generator vi, but it might be an overkill.  Also, its output is specified in volts.  Is there a simple way to convert this voltage into Boolean “high” and “low” levels?  Any better ideas or suggestions to try?
    If anyone could provide some guidance on this issue, it would be greatly appreciated.
    We are using Labview 2010 SP1.
    Thank you.
    Using Labview 7.0 and 2010 SP1 with Windows XP and 7.

    Hi Jack,
    Thank you for your reply.  I was looking over the topic you directed me to and will continue to do so.  I had install DAQ as it wasn't previously installed.  I had a few questions regarding that.
    I setup my own vi similar to your capture in the other topic, as far as I can tell.  I was trying to create a virtual channel to use, however I am unable to do so.  This would be for the "counter" control.  It appears this needs a physical channel.  Is there something I'm missing when trying to do that (creating a virtual channel)?  I may have read the info about DAQ wrong, but I thought I could create a virtual channel and use that, but I am unable to do so right now.  I don't even see a tab for it under MAX when trying to create it (as I see in the tutorial I am reading and is mentioned in help). 
    If you could provide any insight into that or what I may be doing wrong, I'd appreciate it.
    Thanks.
    Using Labview 7.0 and 2010 SP1 with Windows XP and 7.

  • BrokenNullCheck

    HttpSession session = request.getSession();
    String wfmsId = request.getParameter("wfmsId");
    if(wfmsId == null && wfmsId.trim().equals(""))
    session.removeAttribute("wfmsID");
    else
    session.setAttribute("wfmsID",wfmsId);
    when i do the code review (using PMD tool) it shows the below description as:
    The null check is broken since it will throw a Nullpointer itself.
    The reason is that a method is called on the object when it is null.
    It is likely that you used || instead of && or vice versa.
    please suggest me.
    Thanks

    AMARSHI wrote:
    so u mean i shud code like dis..
    if(wfmsId == null && wfmsId.equals(""))No. And stop using non-words like "dis."
    means if it is null then it has nothing to trim!!No, the above code meands if the reference value is null AND the object pointed to by the reference is an empty String object, then do something. It should be obvious that it's impossible for both of these conditions to be true. It's like saying, "If your hand is empty, and the thing in your hand is an apple."
    Review. Basic. Boolean. Logic.
    then why it dosnt throws any compiler exception?The compiler doesn't know what value will be there at runtime, but it is already telling you that your logic doesn't make sense. It's legal Java syntax, but it shows a flaw in your thinking.
    and moreever this comes as a priority bug as 3I have no idea what that means.
    Edited by: jverd on Jul 11, 2008 12:21 AM

  • Does bitwise operation on boolean datatypes work like logical operation ?

    Does bitwise operation on boolean datatypes work like logical operation ?
    For example, in the following code, how is each bitwise operation (say) 'b1 & b2' evaluated ?
    1) by converting the values of b1 (true) and b2 (false) to binary and doing '&' on them OR
    2) just treating it as a logical operation (i.e. similar to &&) where both have to be equal to be true
    Also, does the outcome of the if condition need to result in a 'true' or 'false' for the relevant message to print ? ....... Just fyi, I tried out this program and it goes to condition 2 but I do not understand why.
    class SSBool {
    public static void main(String[] args) {
    boolean b1 = true;
    boolean b2 = false;
    boolean b3 = true;
    if (b1 & b2 | b2 & b3 | b2)
    System.out.println ("condition 1");
    if (b1 & b2 | b2 & b3 | b2 | b1)
    System.out.println ("condition 2");
    Thank you,
    AG

    The Java Tutorial (always my first stop if I need an answer) says :
    "When both operands are boolean, the operator & performs the same operation as &&."
    That your program goes to condition 2 is obvious because the last test in the if-clause if (b1 & b2 | b2 & b3 | b2 | b1) looks at b1 which is true...

  • Can Visual Composer make decisions based on boolean logic?

    I need to know if I can use Visual Composer to manipulate data results based on boolean logic.  Basically, if a  month is less than the current month, I want a formula to dispay A instead of B. Can this be done? 
    Can I also say, if current month is greater than this month then hide values, else show values?

    In that case you don't need VC. I would then directly do that with BEx Query Designer and the use of a formula and boolean operators there. Here is the help of how you can achieve that:
    http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm
    Once you created sthe query this way, you can use the BEx Analyzer to embed it in Excel, and then use Information Broadcasting to schedule the calculations.
    Of course if your requirements change and displayint that data in VC is good enough, then you can still go as mentioned in my answers above

  • Compound boolean logic scripting

    Greetings!  I would like to pick everyone's brains for how one might implement compound boolean logic scripting in LabVIEW ... specifically LabVIEW-RT.
    My application is an in-vehicle data acquistion and logging setup.  The app is setup so that the user provides a configuration file which is the list of channels (GPS, DAQ, CAN) that they wish to record...so this means there isn't any hard coded variable but an array of clusters built from the configuration file.
    A mode of operation is a 'trigger' mode, which means the logger doesn't record anything until a trigger has occured.  Currently the user provides a simple comparator (0=lessthan, 1=equalto, 2=greaterthan, else=none), and the trigger value.
    The users want to be able do compound conditions like PARAMETER <= x OR Parameter >= y ... possiblly even between 2 different data points like PARAMETER_A <= x AND PARAMETER_B >=y.
    Any comment, hints, tips, suggestions ?
    Thanks!
    Jason Stallard

    Jason,
    It's interesting how often the problem of text-based scripting to drive LV pops up.
    I had a problem with similar properties: given a set of data and an
    arbitrary set of rules, substitute data into each rule and see if it
    evaluates to true or false.  This is used to provide directions
    from engineers to operators on how to perform failure analysis and
    recovery, without the engineer needing to be present.
    The problem that I ran into turns out to not be in evaluating the data
    and rules, but in parsing the arbitrary input equation.  There
    just isn't any general way inherent to LV to parse an arbitrary text
    language into an intermediate form (like a postfix expression or an
    abstract syntax tree).  A relative lack of recursion makes it a
    little more painful as well.
    I can't release my code, but it essentially had three parts:
    1.  In a given rule in infix form (variableA<7, for instance),
    perform macro replacement.  Essentially, substitute values for
    variable names, perform file lookups, etc.
    2.  Transform the substituted infix equation into a much easier to
    deal with postfix equation.  (Thanks to Mike Porter for this
    suggestion as well).  This step can be non-trivial.  I'm
    currently building an editor that will build equations more easily,
    sparing my engineers much pain.
    3.  Evaluate the postfix equation for a single true/false
    result.  This algorithm should be available in many books, but I
    adapted the one from an earlier version of this book:
    http://www.amazon.com/gp/product/0201702975/qid=11​37608429/sr=2-3/ref=pd_bbs_b_2_3/103-3337903-13870​46?s=books&v=glance&n=283155
    It also contains a short description of a stack-based parser that's fairly easy to implement for step 2.
    Anyway, there's my 2 cents.  Maybe someday I'll find time to write
    that LV based parser generator to "simplify" all of this   Good
    luck!
    Joe Z.

  • Implies Boolean Logic

    Hi guys,
    just a bit stuck on something.
    In my programs i've been using a shift register and a not-implies boolean function to perform an action once only, when a value changed from false to true
    in boolean logic how would I spot a change so that a true to false change will provide true, but other states false?
    any help very much appreciated - got a bit of a hangover and my brain isn't flying at full-mast!
    cheers!

    Since the state of (one true/one false) has a different output depending on the motor running or not, you need a shift register to store the motor state. Only if both are equal, the state should change.
    The attached codelet shows one possibility.
    (edit: replaced booleans with counters in image. Thanks tst)Message Edited by altenbach on 04-03-2005 02:14 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Motor1.gif ‏3 KB

  • Creating Boolean Logic formulas within Cell Editor

    Good afternoon,
    Does anyone know if boolean logic works within the cell editor?  I want to create boolean logic to choose a different help cell based on a condition.

    Hi,
    Check these help.sap links
    http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c1/759b3c4d4d8d15e10000000a114084/content.htm
    Regards,
    DST

  • Boolean logic

    Hey, whats the best way to represent a minus and divide in in java for a boolean equation? Say i have x-y, i sub a matrix of values in {(0,0),(1,0),(0,1),(1,1)} and i want o return their logical boolean result. So if i do it for plus i use the OR gate, and multiplication uses the AND gate.
    Do i simply reverse the result for a plus?
    Podger

    haha tis alright figured it out

  • Boolean Logic in the Page

    Hi!
    I have a beginners problem that seems very trivial, but I can simply not find the solution. How do you do boolean logic in a JSF page. I want to be able to hide some buttons depending on some data in the bean, but I do not know how to do that. I guess what I am after is the equivalent of the Struts <logic:equal> and <logic:notEqual> tags.
    Regards,
    Magnus

    Use rendered attribute.
    For example:
    <h:commandButton value="Edit" action="edit" rendered="#{MyBean.editable}" />
    In this example, editable should be a bean property with type Boolean and public getter.
    Generally, you can use any expression based on JSF EL (JavaServer Faces Expression Language).
    For example:
    <h:commandButton value="Create" action="createUser" rendered="#{MyBean.userName == null }" />

  • Boolean Logic in Workflows?

    Is it possible to perform any boolean logic in a Podcast Producer workflow? I'd like to set up a workflow that can potentially take in .flv files and pipe them through ffmpeg using the pcastaction shell command. I need to be able to check the file extension and if it's .flv then run the shell command, otherwise carry on normally.
    Thanks,
    Jason

    It's not possible to do branching or conditional logic directly in the Xgrid tasks. But, for the scenario you described, you could write a shell task that determines if the input file is Flash video and then pre-process with ffmpeg, or return immediately if not.

Maybe you are looking for

  • XI 3.0 Sender SOAP Adapter Default XI Parameters

    Hi all, I've noticed when posting to an inbound comm channel using the sender SOAP adapter that unless I specify a namespace and interface under the 'Default XI Parameters', an error is returned indicating I need to specify default values for the nam

  • Keyboard shortucts not working correctly in several programs since Leopard

    Since upgrading to Leopard, certain keyboad commands no longer work. I read since Expose uses the F9, F10 and F11 keys, these may not work in other programs. Final Cut Express recommended switching those keys to Control-F9, Control-F10, and Control-F

  • HP PSC 1410 AII IN ONE

    I HAVE BEEN HAVING PROBLEM OF GETTING VERY LIGHT  SCANS WITH MY 1410 ALL IN ONE PRINTER FRONT LEFT CORNER SCANS ARE OVER EXPOSED(LIGHT/DIM) AND THE REST OF THE SCAN PAGE IS SATISFACTORY. HAVE ALSO OBSERVED A TRANSPARENT PATCH ON SCANNING BED WHICH OT

  • Anyone know how to hide the tabbar when rotated?

    I was told that if you are using a tabbarcontroller, and you want to hide it during rotation, you should override didRotateFromInterfaceOrientation and resize the view inside it and also hide the tabbar itself. But how do you hide the tabbar?

  • Still photo quality worse after cropping

    I've imported tens of photo's (jpeg) in order to make a titlesequence, the photo's appearing as small rectangles on the right side of the screen, the titles on the left. While in full screen the photos are excellent, after cropping they are lousy. Ho