1 / 25

Logical and Relational Operation Session 5

Logical and Relational Operation Session 5. Course : T0974 Algorithm & Object-Oriented Programming I Year : 2011. Learning Outcomes.

booth
Download Presentation

Logical and Relational Operation Session 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Logical and Relational OperationSession 5 Course : T0974 Algorithm & Object-Oriented Programming I Year : 2011

  2. Learning Outcomes After taking this course, student should be expected to apply and demonstrate using Relational and comparator operator, Logical operator and bitwise operator.

  3. Lecture outline • Relational & Comparator procedure • Relational & Comparator operator • Logic & Boolean procedure • Logic & Boolean operator • Truth table • Bitwise Operation

  4. Relational procedure • Relational procedure == Comparator procedure. • Comparing two values. • Using 6 relational/comparator operator. • The result has Boolean type. • The values have number, ASCII, or String data type.

  5. Comparator operator

  6. Comparator operator • Character can be compared by refering to its ASCII number. • Example: ‘a’ is more bigger than ‘A’ because ASCII number for ‘a’ (97) is bigger than ASCII number for ‘A’ (65). • Word can be compared by String helper. • Comparator operator is different than asssignment operator. X = 14  store 14 to X. X == 14  compare if X is equal to 14.

  7. Comparator Operation

  8. Logic/Boolean Procedure • Logical procedure == Boolean procedure. • Execute 1 or 2 logic values. • It has 4 types Logic/Boolean operator. • The result has Boolean data type. • Truth table

  9. Boolean Operator

  10. NOT (!) • Operator not (!) inverts the original value. • true  false and false  true

  11. AND (&&) • AND Operator (&&) is true when all of its operands are true. • If one of its operand is false, then AND is false.

  12. OR (||) • OR (||) Operator is true if one of every its operand is true. • If all of its operands become false then OR is false.

  13. XOR (^) • Operator XOR (^) is true when both if its operands has different condition. • When its operands has same condition then XOR is false.

  14. Tabel Kebenaran: Demo

  15. Thruth Table: Demo

  16. Thruth table: Leap Year

  17. Did You Know? • When evaluating p1&&p2, Java evaluates p1 first. • If p1 is true then Java evaluates p2. • If p2 is false then Java doesn’t evaluate p2. • When evaluating p1||p2, Java evaluates p1 first • If p1 is true then Java doesn’t evaluate p2. • If p1 is false then Java evaluates p2.

  18. Advanced Learning • Bit : the smallest unit in data. • 1 byte = 8 bits. • 1 bit has 0 or 1. • Java support bitwise operator to do bit shift. • Example : 0000 0000  0 0000 1000  8 0000 0001  1 0001 0000  16 0000 0010  2 0010 0000  32 0000 0011  3 0100 1101  77 0000 0100  4 1111 1111  255

  19. Advanced Learning • Bit’s values is same as boolean • 1 : true • 0 : false • Its procedure is same as logical procedure. &  && (AND) |  || (OR) ^  ^ (XOR) ~  ! (NOT/NEGATE) • Additional operator << : shift left (unsigned) >> : shift right (signed) >>> : shift right (unsigned)

  20. Advanced Learning

  21. Advanced Learning • Shorthand for bitwise operation : &=, |=, ^=, <<=, >>=, >>>= • Bitwise only can be used for real number like : byte, short, int and long. • Bitwise for Char type converts to int which refer to ASCII number.

  22. Advanced Learning

  23. Advanced Learning

  24. References • Introduction to Java Programming. 8ed. Liang. 2011. p96-97 • Dasar Pemrograman Java 2. Abdul Kadir. 2004. p76-83 • The Complete Reference Java. 5ed. Herbert Schildt. 2005. p62-76 • Java 2 Weekend Crash Course. Julio Sanchez. 2002. p85-96 • Bitwise: • http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op3.html • http://www.sap-img.com/java/java-bitwise-logical-operators.htm • http://www.leepoint.net/notes-java/data/expressions/bitops.html • http://www.javabeginner.com/java-operators.htm

More Related