65

lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 2: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 3: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

C

Page 4: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 5: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 6: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

printf("hello,world\n");

Page 7: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 8: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 9: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 10: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 11: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 12: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 13: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 14: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 15: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 16: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 17: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 18: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 19: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 20: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

while(true){printf("hello,world\n");}

Page 21: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 22: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 23: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 24: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 25: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 26: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 27: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 28: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 29: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 30: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 31: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

for(inti=0;i<50;i++){printf("hello,world\n");}

Page 32: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 33: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 34: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 35: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 36: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 37: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 38: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 39: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

if(x<y){printf("xislessthany\n");}elseif(x>y){printf("xisgreaterthany\n");}else{printf("xisequaltoy\n");}

Page 40: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

#include<stdio.h>

intmain(void){printf("hello,world\n");}

Page 41: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

01111111 01000101 01001100 01000110 00000010 00000001 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000010 00000000 00111110 00000000 00000001 00000000 00000000 00000000 10110000 00000101 01000000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 11010000 00010011 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 00111000 00000000 00001001 00000000 01000000 00000000 00100100 00000000 00100001 00000000 00000110 00000000 00000000 00000000 00000101 00000000 00000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000 11111000 00000001 00000000 00000000 00000000 00000000 00000000 00000000 11111000 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00001000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000011 00000000 00000000 00000000 00000100 00000000 00000000 00000000 00111000 00000010 00000000 00000000 00000000 00000000 00000000 00000000 00111000 00000010 01000000 00000000 00000000 00000000 00000000 00000000 00111000 00000010 01000000 00000000 00000000 00000000 00000000 00000000 00011100 00000000 00000000 00000000 00000000 00000000 00000000 00000000

...

Page 42: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

source code

Page 43: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

machine code

Page 44: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

source code

compiler

machine code

Page 45: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

CS50 IDEcs50.io

Page 46: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 47: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point
Page 48: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

clanghello.c

./a.out

Page 49: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

clang-ohellohello.c

./hello

Page 50: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

makehello

./hello

Page 51: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

cd

ls

mkdir

rm

rmdir

...

Page 52: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

get_char

get_double

get_float

get_int

get_long_long

get_string

...

Page 53: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

bool

char

double

float

int

longlong

string

...

Page 54: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

amazon.com

Page 55: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

integer overflow

Page 56: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

I I I I I I I 0 128 64 32 16 8 4 2 1

Page 57: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

I I I I I I I I 128 64 32 16 8 4 2 1

Page 58: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

00000000128 64 32 16 8 4 2 1

Page 59: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

wikia.com

Page 60: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

youtube.com

Page 61: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

nytimes.com

Page 62: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

floating-point imprecision

Page 63: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

integer overflow

Page 64: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point

kotaku.com

Page 65: lecture1 - CS50cdn.cs50.net/2017/fall/lectures/1/lecture1.pdf128 64 32 16 8 4 2 1 I I I I I I I I 128 64 32 16 8 4 2 1 00000000 128 64 32 16 8 4 2 1 wikia.com youtube.com floating-point