Memória Interna e Código de Hamming
Memória Interna e Código de Hamming
0 0 1 1 0
Memória gravada
0 1 1 1 0
Memória lida
Preparo do código:
Para uma palavra original de M bits que queremos gravar
na memória, calculamos K bits adicionais, obtidos em
função dos M bits originais.
Forma-se um código de M + K bits. Esse código é gravado
na memória.
Detecção:
Para uma palavra de M bits, acrescentamos K = 1 bit a
mais, que depende dos M bits.
Correção:
Para uma palavra de M bits, acrescentamos K bits a mais,
onde K depende de M. Veremos isso.
Se há apenas um bit errado no código formado por M + K
bits, então o método que veremos consegue dizer qual
esse bit errado e pode corrigi-lo sem ter que ler de novo.
M bits 1 bit
palavra bit paridade
O bit paridade é escolhido de tal modo que o número de 1’s do
código formado (M + 1 bits) é par.
Exemplo 1: A palavra contém um número par de 1’s. Então o
bit paridade vale 0. Assim, o código (4 + 1 bits) contém um
número par de 1’s.
0 0 1 1 0
palavra bit paridade
M bits 1 bit
palavra bit paridade
O bit paridade é escolhido de tal modo que o número de 1’s do
código formado (M + 1 bits) é par.
Exemplo 2: A palavra contém um número ímpar de 1’s. Então
o bit paridade vale 1. Assim, o código (4 + 1 bits) contém um
número par de 1’s.
1 0 1 1 1
palavra bit paridade
0 0 1 1 ?
palavra bit paridade
o bit paridade x5 = 0 ⊕ 0 ⊕ 1 ⊕ 1 = 0
0 0 1 1 0
palavra bit paridade
0 1 1 1 0
palavra bit paridade
Calculamos a paridade do código lido: paridade ímpar: erro!
Tem que ler de novo.
0 0 1 1 0
palavra bit paridade
0 0 1 1 1
palavra bit paridade
Calculamos a paridade do código lido: paridade ímpar: erro!
Tem que ler de novo.
0 0 1 1 0
palavra bit paridade
1 1 1 1 0
palavra bit paridade
Paridade deu par: OK? O método não detecta erro quando há
um número par de bits errados.
Source: Wikipedia
Hamming queria fazer Engenharia, mas não tinha recursos. Acabou fazendo
Matemática pois conseguiu uma bolsa na Universidade de Chicago, onde não havia
curso de engenharia. Fez depois mestrado e doutorado em Matemática. Trabalhou na
Bell Labs e inventou o famoso código de Hamming. Não se arrependeu de ter feito
Matemática, pois o profundo conhecimento teórico o ajudou a resolver um problema
de pesquisa de vanguarda: se o computador sabe detectar um erro de memória, por
que não pode corrigi-lo? Hamming recebeu o Turing Award em 1968.
Source: Wikipedia
& %
C
& %
& %
C
& %
& %
C
& %
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Supomos que após a leitura do código de Hamming, apenas um bit pode estar errado.
Não consideramos erros de 2 ou mais bits.
Devemos ter: 2K − 1 ≥ M + K .
Portanto K deve ser tal que 2K − 1 − K ≥ M.
Então dado M, como calculamos K ?
Dado M, obtemos o menor K que satisfaz
2K − 1 − K ≥ M.
Exemplo: para M = 4, obtemos o menor K = 3 e temos
23 − 1 − 3 = 4 ≥ 4.
Exemplo: para M = 8, obtemos o menor K = 4 e temos
24 − 1 − 4 = 11 ≥ 8.
Temos 2K ≥ M + 1 + K > M.
Para M = 2s , 2K > M ou 2K > 2s .
Assim temos K > s.
Podemos fazer K = s + 1 = log M + 1.
Para M grande, o overhead é menor. Mas lembre-se que o
código só funciona para erro de um só bit no código.
m1 m2 m3 m4 m5 m6 m7 m8
x1 = a determinar
x2 = a determinar
x3 = m1
x4 = a determinar
x5 = m2
x6 = m3
x7 = m4
x8 = a determinar
x9 = m5
x10 = m6
x11 = m7
x12 = m8
x1 = x3 ⊕ x5 ⊕ x7 ⊕ x9 ⊕ x11
x2 = x3 ⊕ x6 ⊕ x7 ⊕ x10 ⊕ x11
x4 = x5 ⊕ x6 ⊕ x7 ⊕ x12
x8 = x9 ⊕ x10 ⊕ x11 ⊕ x12
A ideia é
Primeiro escolhemos vários subconjuntos desse conjunto
de bits
Vamos exigir que a paridade seja par para cada um
desses subconjuntos
Ao invés de um bit paridade, teremos vários bits de
paridade. Isso será útil conforme veremos mais tarde.
Vejamos como escolher esses subconjuntos.
0 a 12 em binário 8 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
0 a 12 em binário 8 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
0 a 12 em binário 8 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
x1 = x3 ⊕ x5 ⊕ x7 ⊕ x9 ⊕ x11
x2 = x3 ⊕ x6 ⊕ x7 ⊕ x10 ⊕ x11
x4 = x5 ⊕ x6 ⊕ x7 ⊕ x12
x8 = x9 ⊕ x10 ⊕ x11 ⊕ x12
0 a 12 em binário 8 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
x1 = x3 ⊕ x5 ⊕ x7 ⊕ x9 ⊕ x11
x2 = x3 ⊕ x6 ⊕ x7 ⊕ x10 ⊕ x11
x4 = x5 ⊕ x6 ⊕ x7 ⊕ x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