Class Notes
(811,485)
United States
(314,604)
Computer Science
(77)
CMPS 12B
(37)
Darrell Long
(34)
Lecture 4
Unlock Document
Computer Science
CMPS 12B
Darrell Long
Spring
Description
CMPS 12B Lecture 4
4/13/2017
(3:204:55)
Announcements
MSI Sessions
Monday: 2:403:40 PM @ Oakes Learning Center
Wednesday: 2:403:40 PM @ Oakes Learning Center; 5:206:20PM
Friday: @ Cowell mobile office, 45PM, ARC Center
All on Piazza
Boundaries
Emails
70100 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)
AB = {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 = uint32t
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