2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
1

Код Хэмминга кодер-декодер

09.12.2010, 21:30. Показов 23293. Ответов 27
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Требуется создать кодер-декодер по коду Хэмминга. Почитал, вроде ничего сложного. Теперь надо написать.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
09.12.2010, 21:30
Ответы с готовыми решениями:

Декодер Хэмминга
Пишу кодер и декодер Хэмминга (15,11). В начале это была одна программа и использовались одни и...

Кодер и декодер Рида-Соломона
Здравствуйте! Дано задание: Кодирование и декодирование укороченного систематического кода...

Код Хэмминга
Прошу объяснить как работает этот код Хэмминга и написать прогу по заданию. Задание. ...

Код Хэмминга
Всем привет, разбираю пример кода Хмминга, подскажите плз, что это за фрагменты void...

27
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 21:34 2
Цитата Сообщение от isakz Посмотреть сообщение
Почитал, вроде ничего сложного.
Так в чём проблема?
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 21:35  [ТС] 3
сам код та я понял, его ж еще написать надо на С++. для меня немного сложно.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 21:38 4
Ну, да, нужно и написать. Какие конкретно вопросы, что не получается?
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 21:40  [ТС] 5
да вот здесь все написано: ошибка при создании кода хэмминга.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 21:51 6
Такое впечатление, что все должны искать, где вы создали ещё тему по этому вопросу. Кроме того, дублирование тем запрещено правилами форума.
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 22:16  [ТС] 7
понятно. задачу решить все равно не могу.

Добавлено через 21 минуту
C++
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// ham.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
 
#define MAXINT 65536
#define SIZE 100
 
int arr[SIZE][SIZE];    // a global array , to contain table information 
int ele=0,ind=0;   // indices to be used in above array
 
 
void summ(int i)
{
        /* The method to initialize contents of global array by power of 2's sum for each entry */
        int j=0; //index no
        if(isPow2(i))   
        {
                /*input no i is of power of 2's form like 1,2,4,8,16...*/
                arr[ele][ind]=calcPow(i); 
                /*calculate what's the power of 2 , in the no, & store to global array*/        
                ind++;
        }
        else
        {
                /*input no i is NOT of power of 2's form  */
                j=findLowerOf2(i);  
                /* try to find just last no , which is of form of power of 2 */
                
                arr[ele][ind]=calcPow(j);
                /* again calculate the power*/
                ind++;
                i=i-j; /* differnce in the no & the last no which is of form of power of 2 */
                /*now call method recursively for the new no (i=i-j) */
                summ(i);
        }
}
 
int isPow2(int i)   
{
        /*if input no is power of two retrun 1 , else 0*/
        if(MAXINT % i==0)
                return 1;       //true
        return 0;       //false
}
 
int calcPow(int i)              
{
        /*Thism ethod returns , what is power of 2 , in a no. 
                which is of form 2 to the power p */
        /* return p , from input of format 2^p */
        int count=-1;
        /* validate */
        if(!isPow2(i))  
                printf("flow error...");
        else
                while(i>0)
                {
                        i/=2;
                        count++;
                }
                
        return count;   
}
 
int findLowerOf2(int i)   
{
        /*a function to calculate the no , JUST below i , which is power of 2 */
        int count=-1;
        
        if(isPow2(i))  
                return pow(2,i);
        else
                while(i>0)
                {
                        i/=2;
                        count++;
                }
 
        
        return pow(2,count);
}
void callSumm(int i)
{
        /* A method to call summ() method , with assertion that
                all global parameters are incremented at each call to summ()
        */
        ind=0;
        summ(i);
        arr[ele][ind++]=-1;
        ele++;
        
}
void dieError()
{
        /* If failure , exit the program*/
        exit(1);
}
 
int howManyTimes(int val,int a[])
{
        /* a method to check that how many times 
                no val is occuring  in array a[]
        */
        int i,count=0;
        for(i=0;a[i]!=-1;i++)
                if(a[i]==val)
                        count++;
        return count;
}
 
void checkInput(int argc,char str[])
{
        int i=0;
        if (argc<2)
        {
                printf("usage: filename.o 'The code string' ");
                printf("
ex.
a.out 110110
");
                dieError();
        }
        for(i=0;i<strlen(str);i++)
                if(!(str[i]=='0' || str[i]=='1'))
                {
                        printf("Please enter a binary string only.....
");
                        dieError();
                }       
}
 
 
int calr(int m)
{
        /*Method to calculate checksum bits for 
                given m , databits
        */
        int r=0;
        for(r=0;r<=m;r++)
                if(m <= pow(2,r)-1-r)
                        return r;
}
 
int isEven(int i)
{
        return i%2==0;
}
 
int main(int argc,char *argv[])
{       
                /* Declaretions ...*/
        /* flag & index variables*/
        int i,j,k=0,flag,temp;
        /* The output codeword container */
        char coded[SIZE];
        int len; //total length of coded word
        int m;  //code bits
        int r;          //check bits
        /* to associate & contain equations of checkbits */     
        int count[SIZE][SIZE]; 
 
        /* validate input  */
        checkInput(argc,argv[1]);  
        
        /*calculate no of check bits required n thus total length */
        m=strlen(argv[1]);
        r=calr(m);
        len=m+r;
 
 
        /* Fill the global container ,  according to the size info
                of m,r & len */
        for(i=1;i<=len;i++)
                callSumm(i);
        
        for(j=0,k=0;j<r;j++)
        {
                for(i=0,k=0;i<len;i++)
                        if(howManyTimes(j,arr[i]))
                                count[j][k++]=i+1;
 
                count[j][k]=-1;
        }
        
        
        /*Fill the code word....,except check bits*/
        for(i=0,j=0;j<len;j++)
        {
                if(!isPow2(j+1))
                        coded[j]=argv[1][i++];
                else
                        coded[j]='x';  //initialize checkbits by character x 
                
        }
 
        /* Now **********
                Frame all equations & solve them
                & fill entries in coded table accordingly
        */
        for(i=0;i<r;i++)
        {
                for(flag=0,j=1;count[i][j]!=-1;j++)
                {
                        temp=count[i][j]-1;
                                if (coded[temp]=='1')
                                        flag+=1;
                                else if (coded[temp]=='0')
                                        flag+=0;
                }       
                        temp=count[i][0]-1;    
                        if (isEven(flag))
                                coded[temp]='0';
                        else
                                coded[temp]='1';
        }
        
        printf("The Hamming coded word for your data is
 ");
        for(i=0;i<len;i++)
                printf("%c",coded[i]);
        printf("
");
 
}

ошибки


1>------ Build started: Project: ham, Configuration: Debug Win32 ------
1>Compiling...
1>ham.cpp
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(20) : error C3861: 'isPow2': identifier not found
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(23) : error C3861: 'calcPow': identifier not found
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(30) : error C3861: 'findLowerOf2': identifier not found
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(33) : error C3861: 'calcPow': identifier not found
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(75) : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'
1> while trying to match the argument list '(int, int)'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(84) : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'
1> while trying to match the argument list '(int, int)'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(100) : error C3861: 'exit': identifier not found
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(121) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(122) : error C2146: syntax error : missing ')' before identifier 'ex'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(124) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(127) : warning C4018: '<' : signed/unsigned mismatch
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(130) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(131) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(132) : error C2146: syntax error : missing ')' before identifier 'dieError'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(144) : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'
1> while trying to match the argument list '(int, int)'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(221) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(222) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(223) : error C2143: syntax error : missing ')' before 'for'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(223) : warning C4552: '<' : operator has no effect; expected operator with side-effect
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(223) : error C2143: syntax error : missing ';' before ')'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(223) : error C2143: syntax error : missing ';' before ')'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(225) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(226) : error C2001: newline in constant
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(228) : error C2143: syntax error : missing ')' before '}'
1>d:\мои документы\visual studio 2008\projects\ham\ham\ham.cpp(228) : error C2143: syntax error : missing ';' before '}'
1>Build log was saved at "file://d:\мои документы\Visual Studio 2008\Projects\ham\ham\Debug\BuildLog.htm"
1>ham - 23 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Добавлено через 33 секунды
путаю ошибка.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 22:19 8
По крайней мере так код из предыдущей темы компилируется:

C++
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
 
#define MAXINT 65536
#define SIZE 100
 
int arr[SIZE][SIZE];    // a global array , to contain table information 
int ele=0,ind=0;   // indices to be used in above array
 
 
int isPow2(int i)   
{
        /*if input no is power of two retrun 1 , else 0*/
        if(MAXINT % i==0)
                return 1;       //true
        return 0;       //false
}
 
int findLowerOf2(int i)   
{
        /*a function to calculate the no , JUST below i , which is power of 2 */
        int count=-1;
        
        if(isPow2(i))  
                return pow(2.0, (double)i);
        else
                while(i>0)
                {
                        i/=2;
                        count++;
                }
 
        
        return pow(2.0,(double)count);
}
 
int calcPow(int i)              
{
        /*Thism ethod returns , what is power of 2 , in a no. 
                which is of form 2 to the power p */
        /* return p , from input of format 2^p */
        int count=-1;
        /* validate */
        if(!isPow2(i))  
                printf("flow error...");
        else
                while(i>0)
                {
                        i/=2;
                        count++;
                }
                
        return count;   
}
 
void summ(int i)
{
        /* The method to initialize contents of global array by power of 2's sum for each entry */
        int j=0; //index no
        if(isPow2(i))   
        {
                /*input no i is of power of 2's form like 1,2,4,8,16...*/
                arr[ele][ind]=calcPow(i); 
                /*calculate what's the power of 2 , in the no, & store to global array*/        
                ind++;
        }
        else
        {
                /*input no i is NOT of power of 2's form  */
                j=findLowerOf2(i);  
                /* try to find just last no , which is of form of power of 2 */
                
                arr[ele][ind]=calcPow(j);
                /* again calculate the power*/
                ind++;
                i=i-j; /* differnce in the no & the last no which is of form of power of 2 */
                /*now call method recursively for the new no (i=i-j) */
                summ(i);
        }
}
 
void callSumm(int i)
{
        /* A method to call summ() method , with assertion that
                all global parameters are incremented at each call to summ()
        */
        ind=0;
        summ(i);
        arr[ele][ind++]=-1;
        ele++;
        
}
 
 
 
 
void dieError()
{
        /* If failure , exit the program*/
        exit(1);
}
 
int howManyTimes(int val,int a[])
{
        /* a method to check that how many times 
                no val is occuring  in array a[]
        */
        int i,count=0;
        for(i=0;a[i]!=-1;i++)
                if(a[i]==val)
                        count++;
        return count;
}
 
void checkInput(int argc,char str[])
{
        int i=0;
        if (argc<2)
        {
                printf("usage: filename.o 'The code string' ");
                printf("ex.a.out 110110");
                dieError();
        }
        for(i=0;i<strlen(str);i++)
                if(!(str[i]=='0' || str[i]=='1'))
                {
                        printf("Please enter a binary string only.....");
                        dieError();
                }       
}
 
 
int calr(int m)
{
        /*Method to calculate checksum bits for 
                given m , databits
        */
        int r=0;
        for(r=0;r<=m;r++)
                if(m <= pow(2.0,(double)r)-1-r)
                        return r;
}
 
int isEven(int i)
{
        return i%2==0;
}
 
int main(int argc,char *argv[])
{       
                /* Declaretions ...*/
        /* flag & index variables*/
        int i,j,k=0,flag,temp;
        /* The output codeword container */
        char coded[SIZE];
        int len; //total length of coded word
        int m;  //code bits
        int r;          //check bits
        /* to associate & contain equations of checkbits */     
        int count[SIZE][SIZE]; 
 
        /* validate input  */
        checkInput(argc,argv[1]);  
        
        /*calculate no of check bits required n thus total length */
        m=strlen(argv[1]);
        r=calr(m);
        len=m+r;
 
 
        /* Fill the global container ,  according to the size info
                of m,r & len */
        for(i=1;i<=len;i++)
                callSumm(i);
        
        for(j=0,k=0;j<r;j++)
        {
                for(i=0,k=0;i<len;i++)
                        if(howManyTimes(j,arr[i]))
                                count[j][k++]=i+1;
 
                count[j][k]=-1;
        }
        
        
        /*Fill the code word....,except check bits*/
        for(i=0,j=0;j<len;j++)
        {
                if(!isPow2(j+1))
                        coded[j]=argv[1][i++];
                else
                        coded[j]='x';  //initialize checkbits by character x 
                
        }
 
        /* Now **********
                Frame all equations & solve them
                & fill entries in coded table accordingly
        */
        for(i=0;i<r;i++)
        {
                for(flag=0,j=1;count[i][j]!=-1;j++)
                {
                        temp=count[i][j]-1;
                                if (coded[temp]=='1')
                                        flag+=1;
                                else if (coded[temp]=='0')
                                        flag+=0;
                }       
                        temp=count[i][0]-1;    
                        if (isEven(flag))
                                coded[temp]='0';
                        else
                                coded[temp]='1';
        }
        
        printf("The Hamming coded word for your data is ");
        for(i=0;i<len;i++)
                printf("%c",coded[i]);
        printf("");
 
}
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 22:36  [ТС] 9
экран появляется на секунды и пропадает, поставил #include <conio.h> и соответственно getch(), пробывал system("pause"). что то не работает.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 22:42 10
https://www.cyberforum.ru/cpp-... 10807.html
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 22:50  [ТС] 11
спасибо, читал, ничего не помогает.

Добавлено через 1 минуту
в начале
C++
1
2
3
4
5
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
в конце
C++
1
2
3
4
5
for(i=0;i<len;i++)
                printf("%c",coded[i]);
        printf("");
getch();
}
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 23:13 12
Какая ОС? Какой компилятор?
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 23:16  [ТС] 13
Windows, Visual C++ 2008 полная версия. сверху еще стоит #include "stdafx.h"-потому что visual.
0
4769 / 2579 / 892
Регистрация: 29.11.2010
Сообщений: 5,581
09.12.2010, 23:18 14
Цитата Сообщение от isakz Посмотреть сообщение
спасибо, читал, ничего не помогает.

Добавлено через 1 минуту
в начале
C++
1
2
3
4
5
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
в конце
C++
1
2
3
4
5
for(i=0;i<len;i++)
                printf("%c",coded[i]);
        printf("");
getch();
}
Так, глядишь, к январю осилишь.
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 23:19  [ТС] 15
не понял юмора?
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 23:23 16
Попробуйте 2 раза getch() или ввести строку какую нибудь с помощью puts.
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 23:34  [ТС] 17
не то и не другое не помогают.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 23:41 18
Как создаёте проект?
Цитата Сообщение от isakz Посмотреть сообщение
еще стоит #include "stdafx.h"-потому что visual.
Обычно это не надо.
0
2 / 2 / 0
Регистрация: 23.10.2010
Сообщений: 111
09.12.2010, 23:42  [ТС] 19
для visual это обязательно. в других да не надо.
0
146 / 146 / 32
Регистрация: 26.10.2008
Сообщений: 782
09.12.2010, 23:49 20
Кто сказал, что это обязательно?
Создайте новый проект, в настройках отметив, что это пустой проект.
0
09.12.2010, 23:49
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
09.12.2010, 23:49
Помогаю со студенческими работами здесь

код Хэмминга
требуется написать программу, (кодер/декодер) код хэмминга (15,11) вводим ошибку срочно

Код Хэмминга
Здравствуйте, помогите написать код Хэмминга на языке новичка, без векторов и т.д. сложного (через...

Код Хэмминга (Dev C++)
всем добрый день; сможете помочь с кодом, надо написать код хэмминга в dev c++, плиииз. по братский

Расширенный код Хэмминга
Всем привет!... Наткнулся на задачу... Сгенерируйте все возможные кодовые слова расширенного кода...

Коды Фано, Хаффмана, Хэмминга, Шеннона, код с проверкой на четность
Помогите пожалуйста!!!!!!очень срочно надо!!!:(:(нужно реализовать коды...

кодер/декодер
здравствуйте. есть небольшой проект - консольное приложение кодера/декодера (сишные файлы...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
20
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru