Top Banner
Binary Computing Introduction Binary, Bits, and Barcodes Daryl DeFord David Freund Dartmouth College Department of Mathematics Johns Hopkins University - Center for Talented Youth Science and Technology Series National Mathematics Awareness Month
136

Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Apr 17, 2018

Download

Documents

trinhbao
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Binary, Bits, and Barcodes

Daryl DeFord David Freund

Dartmouth CollegeDepartment of Mathematics

Johns Hopkins University - Center for Talented YouthScience and Technology Series

National Mathematics Awareness Month

Page 2: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Abstract

Abstract

Every aspect of computing is managed through the uses of zeros andones. In this workshop we will explore the mathematics of thesebinary representations, using them to count and compute efficiently.We will also see how similar ideas are used for a diverse range oftasks from designing barcodes to making skip resistant CDs andsending secure messages from outer space.

Page 3: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Outline

1 Introduction

2 Counting

3 BarcodesChecksums

4 Error CorrectionHamming Codes

5 Conclusion

Page 4: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

What is computer science?

Computer science is no more about computers thanastronomy is about telescopes, biology is about microscopes orchemistry is about beakers and test tubes. Science is not abouttools. It is about how we use them, and what we find out whenwe do.1

1Michael Fellows (1991)

Page 5: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

What is computer science?

Computer science is no more about computers thanastronomy is about telescopes, biology is about microscopes orchemistry is about beakers and test tubes. Science is not abouttools. It is about how we use them, and what we find out whenwe do.1

1Michael Fellows (1991)

Page 6: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Mathematical Data Analysis

• One of the fastest growing careers in the U.S.

• New major at Dartmouth

• Skills needed:• Calculus• Linear Algebra• Probability and Statistics• Programming skills• Interest in applications*

• *or interest in the underlying mathematics

Page 7: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Mathematical Data Analysis

• One of the fastest growing careers in the U.S.

• New major at Dartmouth

• Skills needed:• Calculus• Linear Algebra• Probability and Statistics• Programming skills• Interest in applications*

• *or interest in the underlying mathematics

Page 8: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Mathematical Data Analysis

• One of the fastest growing careers in the U.S.

• New major at Dartmouth

• Skills needed:• Calculus• Linear Algebra• Probability and Statistics• Programming skills• Interest in applications*

• *or interest in the underlying mathematics

Page 9: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Mathematical Data Analysis

• One of the fastest growing careers in the U.S.

• New major at Dartmouth

• Skills needed:• Calculus• Linear Algebra• Probability and Statistics• Programming skills• Interest in applications*

• *or interest in the underlying mathematics

Page 10: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Mathematical Data Analysis

• One of the fastest growing careers in the U.S.

• New major at Dartmouth

• Skills needed:• Calculus• Linear Algebra• Probability and Statistics• Programming skills• Interest in applications*

• *or interest in the underlying mathematics

Page 11: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Braess’ Paradox

Theorem (Braess (1968) and Steinberg and Zangwill (1983))

Adding additional roads between two points may lead to longer averagedriving times. Conversely, closing roads between two points can decreaseaverage travel times.

Page 12: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Introduction

Communication Latency

• Parallel Computing

• Communication Latency

• Data Storage

Page 13: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

How high can you count on your fingers?

Rules

• Work with your group

• No skipping numbers

• Static gestures: no moving

• Just use your fingers

http://i.imgur.com/Mps79UZ.jpg

Page 14: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

How high can you count on your fingers?

Rules

• Work with your group

• No skipping numbers

• Static gestures: no moving

• Just use your fingershttp://i.imgur.com/Mps79UZ.jpg

Page 15: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 16: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 17: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 18: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

21

20

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 19: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 20: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

23

2221

20

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 21: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 22: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 23: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 24: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 25: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Numbers

• Represent numbers using only0 and 1

• Need to decide number ofdigits (bits) in advance

• Each bit can be 0 or 1

2322

2120

Examples: (4 bits)

• 0000 represents 0

• 0100 represents 1 · 22 = 4

• 1010 represents1 · 23 + 1 · 21 = 8 + 2 = 10

Counting in binary:

• 10 fingers = 10 bits

• Bent finger = 1

• Unbent finger = 0

We can count to 1023 !

Page 26: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

History and Applications of Binary

• Horus-eye fractions (2400 BC)

renegadetribune.com/the-magical-world-of-ancient-egypt/

• I Ching hexagrams (900 BC)

commons.wikimedia.org/wiki/File:Iching-hexagram-64.svg

• Gottfried Leibniz (1679)

• Modern computing

stuffpoint.com/computers/image/387779/

binary-number-tunnel-wallpaper/

Page 27: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

History and Applications of Binary

• Horus-eye fractions (2400 BC)

renegadetribune.com/the-magical-world-of-ancient-egypt/

• I Ching hexagrams (900 BC)

commons.wikimedia.org/wiki/File:Iching-hexagram-64.svg

• Gottfried Leibniz (1679)

• Modern computing

stuffpoint.com/computers/image/387779/

binary-number-tunnel-wallpaper/

Page 28: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

History and Applications of Binary

• Horus-eye fractions (2400 BC)

renegadetribune.com/the-magical-world-of-ancient-egypt/

• I Ching hexagrams (900 BC)

commons.wikimedia.org/wiki/File:Iching-hexagram-64.svg

• Gottfried Leibniz (1679)

• Modern computing

stuffpoint.com/computers/image/387779/

binary-number-tunnel-wallpaper/

Page 29: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

History and Applications of Binary

• Horus-eye fractions (2400 BC)

renegadetribune.com/the-magical-world-of-ancient-egypt/

• I Ching hexagrams (900 BC)

commons.wikimedia.org/wiki/File:Iching-hexagram-64.svg

• Gottfried Leibniz (1679)

• Modern computing

stuffpoint.com/computers/image/387779/

binary-number-tunnel-wallpaper/

Page 30: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

111

0010+1011

1101

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 31: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

111

0010+1011

110

1

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 32: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+1011

11

01

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 33: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+1011

1

101

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 34: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 35: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

111

0011+0010

0101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 36: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

111

0011+0010

010

1

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 37: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+0010

01

01

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 38: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+0010

0

101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 39: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 40: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

11111

0111+1110

10101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 41: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

11111

0111+1110

1010

1

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 42: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

11

1

11

0111+1110

101

01

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 43: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

1

11

11

0111+1110

10

101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 44: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+1110

1

0101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 45: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 46: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×1011

0000+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 47: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 48: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

010110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 49: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 50: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×1110

11101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 51: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×11101110

1110

0

+1110

00

1100010

7×1428

+7

0

98

Page 52: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×111011101110

0+1110

00

1100010

7×1428

+7

0

98

Page 53: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×111011101110

0

+1110

001100010

7×1428

+7

0

98

Page 54: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Binary Arithmetic

Adding binary numbers:

1

11

0010+10111101

2+1113

1

11

0011+00100101

3+25

111

11

0111+111010101

7+1421

Multiplying binary numbers:

0010×10110000

+1011

0

10110

2×1122

0111×111011101110

0

+1110

00

1100010

7×1428

+7

0

98

Page 55: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

IEEE Standard

What about other numbers?

• It is possible to design a systemto allow for:• Negative numbers• Decimals• π• Letters• Other characters: !, #, %

• Need to establish standardrepresentation

• The IEEE Standard forFloating-Point Arithmetic wasestablished in 1985

• Current version is from 2008

Page 56: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 57: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 58: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 59: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 60: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 61: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

717

1 Write 17 in binary: 10001

2 Square:

7→ 72 → 74 → 78 → 716

3 717 = 716 · 74 This required 5 multiplications

instead of 16

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 62: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

615

1 Write 15 in binary: 1111

2 Square:

6→ 62 → 64 → 68

3 615 = 68 · 64 · 62 · 64 This required 6 multiplications

instead of 14

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 63: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

615

1 Write 15 in binary: 1111

2 Square:

6→ 62 → 64 → 68

3 615 = 68 · 64 · 62 · 64 This required 6 multiplications

instead of 14

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 64: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

615

1 Write 15 in binary: 1111

2 Square:

6→ 62 → 64 → 68

3 615 = 68 · 64 · 62 · 64 This required 6 multiplications

instead of 14

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 65: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

615

1 Write 15 in binary: 1111

2 Square:

6→ 62 → 64 → 68

3 615 = 68 · 64 · 62 · 64 This required 6 multiplications

instead of 14

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 66: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Counting

Fast Exponentiation

Question: How do we compute large numbers with few multiplications?

615

1 Write 15 in binary: 1111

2 Square:

6→ 62 → 64 → 68

3 615 = 68 · 64 · 62 · 64 This required 6 multiplications

instead of 14

• Use powers of 2

1 Write exponent in binary2 Square the base repeatedly

• Requires fewer multiplications

717 : 5 < 16

615 : 6 < 14

Page 67: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Barcode History

Figure: The phrase “JHU CTY Math” encoded as a standard barcode.

Page 68: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Barcode Process

1 Encode phrase in binary• Simplified codes:

• A→ 0001, B → 0010, etc.

• A.S.C.I.I.

2 Express the code in a machine readable (“scannable”) format• UPC• ISBN• QR codes• ...

Page 69: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Barcode Process

1 Encode phrase in binary• Simplified codes:

• A→ 0001, B → 0010, etc.

• A.S.C.I.I.

2 Express the code in a machine readable (“scannable”) format• UPC• ISBN• QR codes• ...

Page 70: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Barcode Process

1 Encode phrase in binary• Simplified codes:

• A→ 0001, B → 0010, etc.

• A.S.C.I.I.

2 Express the code in a machine readable (“scannable”) format• UPC• ISBN• QR codes• ...

Page 71: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Barcode Process

1 Encode phrase in binary• Simplified codes:

• A→ 0001, B → 0010, etc.

• A.S.C.I.I.

2 Express the code in a machine readable (“scannable”) format• UPC• ISBN• QR codes• ...

Page 72: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Direct Encoding

• Take a look at the reference sheet in your packet

• Example:• We want to encode the phrase “Welcome! ,”• Work one letter at a time to get:

10111−00101−01100−00011−01111−01101−00101−11011−11111

Page 73: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Direct Encoding

• Take a look at the reference sheet in your packet

• Example:• We want to encode the phrase “Welcome! ,”• Work one letter at a time to get:

10111−00101−01100−00011−01111−01101−00101−11011−11111

Page 74: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Direct Encoding

• Take a look at the reference sheet in your packet

• Example:• We want to encode the phrase “Welcome! ,”• Work one letter at a time to get:

10111−00101−01100−00011−01111−01101−00101−11011−11111

Page 75: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Method

• If we just want to express digits we can simplify our representation.

• There are exactly 10 binary words with 5 bits that have 2 ones.

Digit 2 in 5 Digit 2 in 5

0 01100 5 001101 11000 6 100012 10100 7 010013 10010 8 001014 01010 9 00011

• Can you spot the pattern?

Page 76: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Method

• If we just want to express digits we can simplify our representation.

• There are exactly 10 binary words with 5 bits that have 2 ones.

Digit 2 in 5 Digit 2 in 5

0 01100 5 001101 11000 6 100012 10100 7 010013 10010 8 001014 01010 9 00011

• Can you spot the pattern?

Page 77: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Method

• If we just want to express digits we can simplify our representation.

• There are exactly 10 binary words with 5 bits that have 2 ones.

Digit 2 in 5 Digit 2 in 5

0 01100 5 001101 11000 6 100012 10100 7 010013 10010 8 001014 01010 9 00011

• Can you spot the pattern?

Page 78: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 79: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 80: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 81: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 82: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 83: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 84: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Example

• We want to encode the digits 314159

• Work one digit at a time to get:• 3→ 10010• 1→ 11000• 4→ 01010• ...

• 10010-11000-01010-11000-00110-00011

Page 85: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

2 in 5 Barcode

Figure: Barcode for 10010-11000-01010-11000-00110-00011. The digits“314159” encoded using the interleaved 2 in 5 code.

Page 86: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

More Complicated Examples

Figure: Components of the ISBN barcode system used for books:https://en.wikipedia.org/wiki/International Standard BookNumber#/media/File:EAN-13-ISBN-13.svg. Note the checksum value at theend of the code.

Page 87: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

More Complicated Examples

Figure: Components of the ISBN barcode system used for books:https://en.wikipedia.org/wiki/International Standard BookNumber#/media/File:EAN-13-ISBN-13.svg. Note the checksum value at theend of the code.

Page 88: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Binary Check Digits

• Not just for barcodes...

• Simplest version of a checksum

• Add up all the individual digits in binary, the check sum is equal tothe last digit.

• In this setting this is just describing whether there is an odd or evennumber of “ones”

• Alternatively, we are forcing the new word to have an even numberof “ones”

• Example:• We want a checksum for 10011• The binary sum is 1 + 0 + 0 + 1 + 1 = 11 so the checksum is 1• Thus we would use the code 10111

Page 89: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Binary Check Digits

• Not just for barcodes...

• Simplest version of a checksum

• Add up all the individual digits in binary, the check sum is equal tothe last digit.

• In this setting this is just describing whether there is an odd or evennumber of “ones”

• Alternatively, we are forcing the new word to have an even numberof “ones”

• Example:• We want a checksum for 10011• The binary sum is 1 + 0 + 0 + 1 + 1 = 11 so the checksum is 1• Thus we would use the code 10111

Page 90: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Binary Check Digits

• Not just for barcodes...

• Simplest version of a checksum

• Add up all the individual digits in binary, the check sum is equal tothe last digit.

• In this setting this is just describing whether there is an odd or evennumber of “ones”

• Alternatively, we are forcing the new word to have an even numberof “ones”

• Example:• We want a checksum for 10011• The binary sum is 1 + 0 + 0 + 1 + 1 = 11 so the checksum is 1• Thus we would use the code 10111

Page 91: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Binary Check Digits

• Not just for barcodes...

• Simplest version of a checksum

• Add up all the individual digits in binary, the check sum is equal tothe last digit.

• In this setting this is just describing whether there is an odd or evennumber of “ones”

• Alternatively, we are forcing the new word to have an even numberof “ones”

• Example:• We want a checksum for 10011• The binary sum is 1 + 0 + 0 + 1 + 1 = 11 so the checksum is 1• Thus we would use the code 10111

Page 92: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 93: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 94: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 95: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 96: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 97: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 98: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Check Words

• Another possibility is to use an entire word as the checksum

• This works particularly well for the 2 in 5 code

• The process is to “stack” the words on top of each other andcompute a binary checksum for each column

• Example:• We want a checkword for the message (HI) 10011− 01010• Matching up the digits we get

123

456

789

• Then we would send the code 10011− 0101011001

Page 99: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

Modular Versions

• For the digit based codes more complicated methods are used:

• For UPC:

3(a1 + a3 + a5 + a7 + a9) + (a2 + a4 + a6 + a8 + a10)

• For ISBN:

10a1 + 9a2 + 8a3 + 7a4 + 6a5 + 5a6 + 4a7 + 3a8 + 2a9 + a10

Page 100: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

What can go wrong?

• What types of errors can these check digits detect?

• What types of errors can these check digits not detect?

• What can we do about it?

Page 101: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

What can go wrong?

• What types of errors can these check digits detect?

• What types of errors can these check digits not detect?

• What can we do about it?

Page 102: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Barcodes

Checksums

What else can go wrong?

• Multiple errors at once

• Transposition errors

• Transcription errors

• Human Errors

• ...

Page 103: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Error Correcting beginning activity

Need two volunteers

Page 104: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

ECC Introduction

• Error correcting codes give us methods for fixing, not just detecting,errors that occur in message transmission

••

Page 105: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Repetition Codes

• The simplest method for error correction is to simply repeat each bitin our message many times

• Once the message is received we let the repeated copies “vote” onthe right answer

• Example:• We want a repetition version of the message 10010• Replace each digit by 5 copies of itself

11111− 00000− 00000− 11111− 00000

Page 106: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Repetition Codes

• The simplest method for error correction is to simply repeat each bitin our message many times

• Once the message is received we let the repeated copies “vote” onthe right answer

• Example:• We want a repetition version of the message 10010• Replace each digit by 5 copies of itself

11111− 00000− 00000− 11111− 00000

Page 107: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Repetition Codes

• The simplest method for error correction is to simply repeat each bitin our message many times

• Once the message is received we let the repeated copies “vote” onthe right answer

• Example:• We want a repetition version of the message 10010• Replace each digit by 5 copies of itself

11111− 00000− 00000− 11111− 00000

Page 108: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Repetition Codes

• The simplest method for error correction is to simply repeat each bitin our message many times

• Once the message is received we let the repeated copies “vote” onthe right answer

• Example:• We want a repetition version of the message 10010• Replace each digit by 5 copies of itself

11111− 00000− 00000− 11111− 00000

Page 109: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 110: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 111: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 112: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 113: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 114: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 115: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 116: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Multi–dimensional Codes

• Begin by rewriting the digits in a rectangle

• Compute a checksum for each row and column

• Rewrite in a line

• Example:• We want a code for 1001101011 0 0

1 1 01 0 1

1 1 11 0 0 11 1 0 01 0 1 0

• Thus we would use the code 100110101111100

Page 117: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Distance

• How do we measure the resiliency of a code?

• The number of errors to reach one binary string from another iscalled the Hamming distance

• This is just the number of bits on which the messages differ

• Example:• The words 11001 and 10101 have a Hamming distance of 2 because

they differ in the second and third digits but the other three are thesame.

Page 118: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Distance

• How do we measure the resiliency of a code?

• The number of errors to reach one binary string from another iscalled the Hamming distance

• This is just the number of bits on which the messages differ

• Example:• The words 11001 and 10101 have a Hamming distance of 2 because

they differ in the second and third digits but the other three are thesame.

Page 119: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Distance

• How do we measure the resiliency of a code?

• The number of errors to reach one binary string from another iscalled the Hamming distance

• This is just the number of bits on which the messages differ

• Example:• The words 11001 and 10101 have a Hamming distance of 2 because

they differ in the second and third digits but the other three are thesame.

Page 120: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Distance

• How do we measure the resiliency of a code?

• The number of errors to reach one binary string from another iscalled the Hamming distance

• This is just the number of bits on which the messages differ

• Example:• The words 11001 and 10101 have a Hamming distance of 2 because

they differ in the second and third digits but the other three are thesame.

Page 121: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Code

• The Hamming code uses

• Start with a 4–digit binary word: abcd

• Compute three check digits:• a+ b+ c = x• a+ b+ d = y• a+ c+ d = z

• Send the message abcdxyz

Page 122: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Code

• The Hamming code uses

• Start with a 4–digit binary word: abcd

• Compute three check digits:• a+ b+ c = x• a+ b+ d = y• a+ c+ d = z

• Send the message abcdxyz

Page 123: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Code

• The Hamming code uses

• Start with a 4–digit binary word: abcd

• Compute three check digits:• a+ b+ c = x• a+ b+ d = y• a+ c+ d = z

• Send the message abcdxyz

Page 124: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Code

• The Hamming code uses

• Start with a 4–digit binary word: abcd

• Compute three check digits:• a+ b+ c = x• a+ b+ d = y• a+ c+ d = z

• Send the message abcdxyz

Page 125: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Code

• The Hamming code uses

• Start with a 4–digit binary word: abcd

• Compute three check digits:• a+ b+ c = x• a+ b+ d = y• a+ c+ d = z

• Send the message abcdxyz

Page 126: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 127: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 128: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 129: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 130: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 131: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 132: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 133: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 134: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Error Correction

Hamming Codes

Hamming Example

• We want to encode the word 1101 = abcd.

• Compute the three check digits:• abc 1, 1, 0→ 0 = x• abd 1, 1, 1→ 1 = y• acd 1, 0, 1→ 0 = z

• Now we send the message 1101010

• If the receiver gets 1001010 they can check the same threecomputations:• 1, 0, 0→ 1 wrong!• 1, 0, 1→ 0 wrong!• 1, 0, 1→ 0 right!

• Since the first two checksums are wrong, the error must haveoccurred at digit b.

Page 135: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Conclusion

Thanks to ...

• Dartmouth CollegeDepartment of Mathematics

• Johns Hopkins UniversityCenter for Talented Youth

Page 136: Binary, Bits, and Barcodes - Mathematics Departmentddeford/Binary_Computing_all.pdf · Binary Computing Introduction What is computer science? Computer science is no more about computers

Binary Computing

Conclusion

THANK YOU!!!