1 introduction two fundamental types in almost any ...guna/15-123s11/lectures/lecture02.pdf · 24...

8
Copyright @ 2011 Frank Pfenning & Ananda Gunawardena Lecture 02 Representing Data 1 Introduction Two fundamental types in almost any programming language are Booleans and integers. Booleans are comparatively straightforward: they have two possible values (true and false) and conditionals to test boolean values. Integers . . . ,-2,-1, 0, 1, 2, . . . are considerably more complex, because there are infinitely many of them. Because memory is finite, only a finite subrange of them can be represented in computers. In this lecture we discuss how integers are represented, how we can deal with the limited precision in the representation, and how various operations are defined on these representations. 2 Binary Representation of Natural Numbers

Upload: others

Post on 13-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Lecture 02

Representing Data

1 Introduction Two fundamental types in almost any programming language are Booleans and integers.

Booleans are comparatively straightforward: they have two possible values (true and

false) and conditionals to test boolean values. Integers . . . ,−2,−1, 0, 1, 2, . . . are

considerably more complex, because there are infinitely many of them. Because memory

is finite, only a finite subrange of them can be represented in computers. In this lecture

we discuss how integers are represented, how we can deal with the limited precision in

the representation, and how various operations are defined on these representations.

2 Binary Representation of Natural Numbers

Page 2: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 3: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 4: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 5: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 6: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 7: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena

Page 8: 1 Introduction Two fundamental types in almost any ...guna/15-123S11/Lectures/Lecture02.pdf · 24 12 6 3 0 2 2 2 2 2 2 2 2 0 0 0 0 , arriving at 11000110 2 We read off the answer,

Copyright @ 2011 Frank Pfenning & Ananda Gunawardena