faculty of computer science © 2006 cmput 229 special-purpose codes binary, bcd, hamming, gray, edc,...

30
Faculty of Computer Science CMPUT 229 © 2006 Special-Purpose Codes Binary, BCD, Hamming, Gray, EDC, ECC

Post on 22-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Faculty of Computer Science

CMPUT 229 © 2006

Special-Purpose Codes

Binary, BCD, Hamming, Gray, EDC, ECC

© 2006

Department of Computing Science

CMPUT 229

Binary-Coded Decimal (BCD) Code

Value Represented Pattern Unsigned Value 1’s complement

0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 Forbidden 1011 11 Forbidden 1100 12 Forbidden 1101 14 Forbidden 1110 15 Forbidden 1111 16 Forbidden

How do we represent 37910 in

BCD code?

310 = 0011BCD

710 = 0111BCD

910 = 1001BCD

37910 = 0011 0111 1001BCD

Inefficient storage.

Complex arithmetic (for hardware).

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code0

1

0

1

0

1

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

00

01

10

11

00

01

10

11

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

000

001

010

011

100

101

110

111

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

000

001

010

011

100

101

110

111

000

001

010

011

100

101

110

111

000

001

010

011

100

101

110

111

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

000

001

010

011

100

101

110

111

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary Code00

01

10

11

0

1

000

001

010

011

100

101

110

111

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

0

1

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

0

1

1

0

0

1

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

00

01

11

10

10

11

01

00

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

000

001

011

010

110

111

101

100

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

000

001

011

010

110

111

101

100

000

001

011

010

110

111

101

100

100

101

111

110

010

011

001

000

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

000

001

011

010

110

111

101

100

0000

0001

0011

0010

0110

0111

0101

0100

1100

1101

1111

1110

1010

1011

1001

1000

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Gray Code

00

01

11

10

0

1

000

001

011

010

110

111

101

100

0000

0001

0011

0010

0110

0111

0101

0100

1100

1101

1111

1110

1010

1011

1001

1000

Hamming distance between two

consecutive words is 1.

Clements, pp. 154

© 2006

Department of Computing Science

CMPUT 229

Binary X Gray Code

Clements, pp. 155

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

Error Detecting Codes

Can detect that a word has been corrupted

– An error always leave a noticeable trace in the encoded

word

• Parity codes

Source

Word Encoder

Source

Code

Word

Received

Code

WordDecoder

Received

Word

Clements, pp. 157

© 2006

Department of Computing Science

CMPUT 229

Parity Error Detecting Codes

Clements, pp. 158

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

Principle of Error-Detecting Code

Clements, pp. 159

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

3-Bit Error Correcting Code

Clements, pp. 159

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

Minimum Hamming Distance in ECC

Clements, pp. 159

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

Block Parity Error-Correcting Code

Clements, pp. 160

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

© 2006

Department of Computing Science

CMPUT 229

Hamming Codes

I4 I3 I2 C3 I1 C2 C1

135 247 6 Cj: Check bit j

Ij: Source bit j

000 Unused

001 C1

010 C2

011 I1

100 C3

101 I2

110 I3

111 I4

0

Clements, pp. 160

© 2006

Department of Computing Science

CMPUT 229

Hamming Codes

I4 I3 I2 C3 I1 C2 C1

135 247 6 Cj: Check bit j

Ij: Source bit j

000 Unused

001 C1

010 C2

011 I1

100 C3

101 I2

110 I3

111 I4

0

C1 = I1 I2 I4

C2 = I1 I3 I4

C3 = I2 I3 I4

Clements, pp. 160

© 2006

Department of Computing Science

CMPUT 229

Hadamard Matrices

+1 +1

+1 -1[H]2 =

Clements, pp. 160

+[H]n +[H]n

+[H]n -[H]n

[H]2n =

+1 +1 +1 +1

+1 -1 +1 -1

+1 +1 -1 -1

+1 -1 -1 +1

[H]4 =

In a Hadamard matrix of order n

each row has a Hamming distance

of n/2 to every other row.

© 2006

Department of Computing Science

CMPUT 229

Hadamard Matrices

Clements, pp. 160

+1 +1 +1 +1

+1 -1 +1 -1

+1 +1 -1 -1

+1 -1 -1 +1[H]8 =

+1 +1 +1 +1

+1 -1 +1 -1

+1 +1 -1 -1

+1 -1 -1 +1

+1 +1 +1 +1

+1 -1 +1 -1

+1 +1 -1 -1

+1 -1 -1 +1

-1 -1 -1 -1

-1 +1 -1 +1

-1 -1 +1 +1

-1 +1 +1 -1

© 2006

Department of Computing Science

CMPUT 229

ECC with Hadamard Matrices

Source

Code

Row

Code Word

000 0 1 1 1 1 1 1 1 1001 1 1 0 1 0 1 0 1 0010 2 1 1 0 0 1 1 0 0011 3 1 0 0 1 1 0 0 1100 4 1 1 1 1 0 0 0 0101 5 1 0 1 0 0 1 0 1110 6 1 1 0 0 0 0 1 1111 7 1 0 0 1 0 1 1 0Clements, pp. 162

© 2006

Department of Computing Science

CMPUT 229

Code Words in a 4-unit Code

COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

Clements, pp. 162