Boolean Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    #1

    Boolean Value

    Good day all! I have one more question and needed some inputs
    from you guys.

    This is regarding condition value (T/F). My program (Driver) prints out condition values in reversed way - which means it supposed to print out 'false' but it's giving 'true' value and vice versa.
    Please refer my Driver class (excerpt):
    Code:
    java.util.List ifs = new java.util.ArrayList();
    
    Instruction insn = jvm.getLastInstruction();     
     ……… 
     ………
       if (insn instanceof IfInstruction) 
    {
         IfInstruction iff = (IfInstruction) insn;
         Object position = insn.getOffset();
         boolean value = iff.getConditionValue();   //THE PROBLEM IS HERE ***
         ifs.add(new Entry(position, value));
         System.out.print(value);
         System.out.println();                                
    }
    Here is the IfInstruction class where I need to get value (T/F) when it encounters IF* statements:
    Code:
      
    int target; /** jump offset */
    boolean conditionValue;  /** value of last evaluation of branch condition */
    /**
       * return which branch was taken. Only useful after instruction got executed
       */
    public boolean getConditionValue() 
      {
         return conditionValue;       
      }
    So my idea is I have to consider reversing the condition so that true actually points to true and false points to false. What do you think? Please advise….many thanks

    Shana
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shana07
    Good day all! I have one more question and needed some inputs
    from you guys.

    This is regarding condition value (T/F). My program (Driver) prints out condition values in reversed way - which means it supposed to print out 'false' but it's giving 'true' value and vice versa.
    Please refer my Driver class (excerpt):
    Code:
    java.util.List ifs = new java.util.ArrayList();
     
    Instruction insn = jvm.getLastInstruction(); 
    ……… 
    ………
    if (insn instanceof IfInstruction) 
    {
    IfInstruction iff = (IfInstruction) insn;
    Object position = insn.getOffset();
    boolean value = iff.getConditionValue(); //THE PROBLEM IS HERE ***
    ifs.add(new Entry(position, value));
    System.out.print(value);
    System.out.println(); 
    }
    Here is the IfInstruction class where I need to get value (T/F) when it encounters IF* statements:
    Code:
     
    int target; /** jump offset */
    boolean conditionValue; /** value of last evaluation of branch condition */
    /**
    * return which branch was taken. Only useful after instruction got executed
    */
    public boolean getConditionValue() 
    {
    return conditionValue; 
    }
    So my idea is I have to consider reversing the condition so that true actually points to true and false points to false. What do you think? Please advise….many thanks

    Shana
    You can reverse the value of a boolean expression using the ! operator.

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #3
      Just this!
      Code:
      value = ! value;
      phew! why I couldn't think about it :)
      Thank u mode.
      Shana

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by shana07
        Just this!

        Code:
        value = ! value;
        phew! why I couldn\'t think about it [img][/img]

        Thank u mode.

        Shana


        Please, PLEASE do not call me mode.

        Comment

        • shana07
          Contributor
          • Jan 2007
          • 280

          #5
          Originally posted by r035198x
          Please, PLEASE do not call me mode.
          So sorry. won't use the name next time.
          again thanks.
          Shana

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by shana07
            So sorry. won\'t use the name next time.

            again thanks.

            Shana


            Some have even started calling me r0 (can you imagine).

            Comment

            Working...