summaryrefslogtreecommitdiff
path: root/1241/CH3/EX3.10/exa3_10.sce
blob: 471e17db264fc6f5a856f6b2a5a87b21acafdf1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Example 3-10//
//Hamming code//
clc
//clears the command window//
clear
//clears all existing variables//
z=0101
//input//
a=0;b=0;c=0;d=0;
//taking the input//
for i=1:7
    x(i)=0
    if i==3 then
       x(i)=1
    end
    if i==6 then
       x(i)=1
    end
end
//establishing even parity at positions 1,3,5,7//
for i=1: 7
    if i==6 then
       continue 
    end
    if x(i)==1 then
       a=a+1
    end
end
d=modulo(a,2)
if (d==1) then
    x(1)=1
end
//establishing even parity at positions 2,3,6,7//
for i=2: 7
    if x(i)==1 then
        b=b+1
    end
end
d=modulo(b,2)
if (d==1) then
    x(2)=1
end
//establishing even parity at positions 4,5,6,7//
for i=5:7
    if (x(i)==1) then
        c=c+1
    end
end
d=modulo(c,2)
if (d==1) then
    x(4)=1
end
//displaying the result//
disp('the hamming code for this data is given as')
for i=1:7
    disp(x(i))
end