Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C language directives
- #if, #ifdef, ifndef, endif, else, elif, include, define, undef, pragma, error, line
- Compile with the -Wall flag!
- WORKSHEET
- int isPrime(int n) {
- int i;
- if(n < 2) return 0;
- for(i=2; i<n/2+1; i++) {
- if(n%i == 0) {
- return 0;
- }
- }
- return 1;
- }
- int sumPrimes(int x) {
- int total = 0;
- int i;
- for(i=2; i<=x; i++) {
- if(isPrime(i)) {
- total += i;
- }
- }
- return total;
- }
- =====
- Lesson 3
- C is a weakly typed language-- associates a type with every value, allows for implicit conversions between some types
- Types only exist at the code level; machine level has no knowledge of types
- A byte is the smallest addressable unit of memory-- 8 bits
- Binary representation of data changes based on data type:
- - unsigned (traditional)
- - two's complement (signed)
- - fixed/floating point
- Hexadecimal used to represent bytes-- 0x00 to 0xFF
- - string ex3: 65 78 33
- Little endian systems (x86)-- MSB is later address: 33 78 65
- Big endian (sun. ibm)-- MSB at earlier address: 65 78 33
- =====
- Bitwise Operators-- | & ^
- || != && are logical operators (byte level)
- >> and << are bitwise shift
- - Left shift: 67 << 5 = 01000011 << 5 = 01100000 = 96
- - Logical right shift (unsigned)
- - Arithmetic right shift (signed) -- pad with zeros if first is 0
- - Arithmetic right shift (signed) -- pad with 1 if first is 1
- =====
- Overflow (when sizes are too small)-- it loops back around since there's only 4 bits / 0 to 15
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement