binary, bits, and barcodes - mathematics departmentddeford/binary_computing_all.pdf · binary...

136
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

Upload: trinhbao

Post on 17-Apr-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

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

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.

Binary Computing

Introduction

Outline

1 Introduction

2 Counting

3 BarcodesChecksums

4 Error CorrectionHamming Codes

5 Conclusion

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)

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)

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

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

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

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

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

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.

Binary Computing

Introduction

Communication Latency

• Parallel Computing

• Communication Latency

• Data Storage

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

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

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 !

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 !

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 !

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 !

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 !

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 !

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 !

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 !

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 !

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 !

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 !

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/

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/

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/

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/

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Binary Computing

Barcodes

Barcode History

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

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• ...

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• ...

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• ...

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• ...

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

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

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

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?

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?

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?

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

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

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

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

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

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

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

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.

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.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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?

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?

Binary Computing

Barcodes

Checksums

What else can go wrong?

• Multiple errors at once

• Transposition errors

• Transcription errors

• Human Errors

• ...

Binary Computing

Error Correction

Error Correcting beginning activity

Need two volunteers

Binary Computing

Error Correction

ECC Introduction

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

••

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

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

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

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

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

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

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

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

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

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

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

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

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.

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.

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.

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.

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

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

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

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

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

Binary Computing

Conclusion

Thanks to ...

• Dartmouth CollegeDepartment of Mathematics

• Johns Hopkins UniversityCenter for Talented Youth

Binary Computing

Conclusion

THANK YOU!!!