Class Notes (811,485)
United States (314,604)
CMPS 12B (37)
Lecture 4

# CMPS 12B Lecture 4: Class 4 - Fundamental Tools, Boolean Arithmetic Premium

6 Pages
46 Views

Department
Computer Science
Course
CMPS 12B
Professor
Darrell Long
Semester
Spring

Description
CMPS 12B Lecture 4 4/13/2017 (3:20-4:55) Announcements MSI Sessions Monday: 2:40-3:40 PM @ Oakes Learning Center Wednesday: 2:40-3:40 PM @ Oakes Learning Center; 5:20-6:20PM Friday: @ Cowell mobile office, 4-5PM, ARC Center All on Piazza Boundaries E-mails 70-100 emails a day. Can’t answer them all. After 10PM, both Darrell and TAs will no longer answer questions On Piazza Don’t ask the same question as other people on Piazza Personal His wife fell down the stairs and needs knee surgery, he’s under stress. Fundamental Tools How do computers do arithmetic? Addition 0101 - 6 0110 - 1011 Multiplication 1010 x 0011 1010 1010  there would be more 0s, but this is called a shift 0000 _ 01110 How to denote negative numbers? Different ways: Two’s Complement High order bit means it’s a negative number subtraction/borrowing Opposite of zero is one, opposite one is zero – One’s complement arithmetic Problem: 0, -0. We don’t like negative 0 Using Two’s Complement: 1111 + 1 0000 (cancels out, no negative 0) Complement everything and add 1 to everything. 0101 0101 1010 1011 + 1 0000 1011 (-5) Modular arithmetic – flip all bits, add 1, that is negative representation for any integer Exercise: do Two’s complement on any number - high order bit is always one >> and << - shift bit right/left Division  Processors do division like long division but with 1s and 0s.  Set notation A U B – A union B A ^ B or A N B– A intersect B A or ~A – A complement or not A A – B or A | B – A minus B or A complement B ~(A U B) – not (A U B) o Venn diagrams  A U B (A union B) = {x| x € A v (or) x € B}  A N B = {x| x € A n x € B}  For programming:  membership operation € – is this in a set? _ (A)  A-B = {x| x € A n x € B} – what is only in A o x € B (with line above it)  1 means you’re in a set, 0 means you’re not o enum dog { rott, dobbie, beagle, doxins, …} (32) 0 1 2 3 o unsigned long = uint32-t  Reminder: A byte is less than a short, etc… o uint32t dogs = 0; o Can you do bitSet(dogs, rott);?  like adding rott to the set dog  If something is already in the set, you don’t create a second entry since it’s binary – you’re in or you’re not  dogs = dogs | 0xl << (int)rott;  0x1 = 1, 1 bit, hexadecimal  dogs = dogs | 0xl << (int)beagle; | Just so some compilers work since operator expects an int. Don’t g
More Less

Related notes for CMPS 12B
Me

OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.