1 / 24

CompSci 105 SS 2005 Principles of Computer Science

Learn about using bits for logical operations, including masking, shifting, parity, and character representation. Understand the software life cycle, basic stages, and verification via loop invariants. Explore the costs associated with software development.

mendozah
Download Presentation

CompSci 105 SS 2005 Principles of Computer Science

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. CompSci 105 SS 2005 Principles of Computer Science Lecture 3 Lecturer: Santokh Singh

  2. Using Bits as Bits Logical Operations Masking and Shifting Parity Representation of Characters Software Life Cycle Basic Stages Specification and Design Verification via Loop Invariants Costs Associated with Software

  3. Octal and Hex in Java int i = 12; System.out.println(i); int i = 012; System.out.println(i); int i = 0x12; System.out.println(i);

  4. Using Bits as Bits Logical Operations Masking and Shifting Parity Representation of Characters Software Life Cycle Basic Stages Specification and Design Verification via Loop Invariants Costs Associated with Software

  5. //First things first – announcements: if (you_enrolled_in _the_105course && you_did_not_pass_COMPSCI101 && you_do_not_have_a_concession_form) { you_MAY_have_been_withdrawn_from_the_course = true; System.out println(“Please check out your fate, urgently.”); }

  6. Logical Operations • NOT x • x AND y • x OR y • x EOR y (x XOR y)

  7. Truth Tables

  8. Bitwise Operations • NOT x • x AND y • x OR y • x EOR y (x XOR y)

  9. Truth Tables

  10. 1 0 1 1 & 1 1 1 0

  11. Exercise • What is the output? int i = 14; System.out.println( i & 1 ); System.out.println( i & 5 );

  12. 0101 1011 1100 1010 0001 1001 1101 0111 0110 0100 0011 0010 1000 10 Q K A 9 8 6 3 7 2 5 4 J Representing a Card 00 ♠ 01 ♣ 10 ♥ 11 ♦

  13. A card in six bits 10 0111

  14. Extracting the Value 10 0111 & 00 1111

  15. Extracting the Suit 10 0111 & 11 0000

  16. Extracting the Suit 10 0111 & 11 0000 What is the suit mask in Hex?

  17. In Java…. public final int valueMask = 0x0f; public final int suitMask = 0x30; public final int suitSpades = 0x00; public final int suitClubs = 0x10; public final int suitHearts = 0x20; public final int suitDiamonds = 0x30; int card = 7 | suitHearts; if ( (card & suitMask) == suitHearts ) System.out.println(“Hearts”);

  18. Extracting the Suit 10 0111 & 11 0000 10 0000

  19. Shifting operations 01100010 << 2 01100010 >> 2

  20. In Java…. public final int suitSpades = 0; public final int suitClubs = 1; public final int suitHearts = 2; public final int suitDiamonds = 3; int card = 7 | ( suitHearts << 4 );

  21. Using Bits as Bits Logical Operations Masking and Shifting Parity Representation of Characters Software Life Cycle Basic Stages Specification and Design Verification via Loop Invariants Costs Associated with Software

  22. Representation of Characters • How many bits do we need?

  23. Refer to Course Book pg. 83

  24. Unicode • 16-bit, Encodes International Alphabets • Low-order 7-bits are ASCII • System.out.println( (int)’E’ ); • www.unicode.org (Ladies & Gentlemen: Assignment 1 given was given out last week).

More Related