Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
redes1-trabalho1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eduardo Machado
redes1-trabalho1
Commits
855f2eb8
Commit
855f2eb8
authored
9 years ago
by
Victor Perszel
Browse files
Options
Downloads
Patches
Plain Diff
funcao de checagem de paridade
parent
da3b4fa9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/submessages.h
+4
-2
4 additions, 2 deletions
include/submessages.h
src/submessages.cpp
+39
-0
39 additions, 0 deletions
src/submessages.cpp
with
43 additions
and
2 deletions
include/submessages.h
+
4
−
2
View file @
855f2eb8
...
...
@@ -40,7 +40,9 @@ class SubMessage{
unsigned
char
*
getData
();
//Retorna os dados
unsigned
char
*
objToString
();
unsigned
char
*
objToString
();
//Transforma o objeto submessage numa string
void
stringToObj
(
unsigned
char
*
);
void
stringToObj
(
unsigned
char
*
);
//Transforma uma string num objeto submessage
int
checkParity
();
// É diferente de 0 caso a paridade esteja errada
};
This diff is collapsed.
Click to expand it.
src/submessages.cpp
+
39
−
0
View file @
855f2eb8
...
...
@@ -128,3 +128,42 @@ void SubMessage::stringToObj(unsigned char* string){
// Passagem da paridade.
parity
=
string
[
size
+
3
];
}
int
SubMessage
::
checkParity
(){
int
**
bitsMessage
;
int
i
,
j
,
bitsParity
[
8
];
unsigned
char
parityTest
;
// Alocação da matriz de bits
bitsMessage
=
new
int
*
[
this
->
getSize
()];
for
(
i
=
0
;
i
<
this
->
getSize
()
;
i
++
){
bitsMessage
[
i
]
=
new
int
[
8
];
// Divide os dados em bits
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsMessage
[
i
][
j
]
=
((
data
[
i
]
>>
(
7
-
j
))
&
0x01
);
}
}
// Soma os bits verticalmente
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsParity
[
j
]
=
0
;
for
(
i
=
0
;
i
<
this
->
getSize
()
;
i
++
){
bitsParity
[
j
]
=
bitsParity
[
j
]
+
bitsMessage
[
i
][
j
];
}
// Caso a soma vertical de uma coluna for par, bitsParity recebe 1,
// caso contrario ele recebe 0.
if
((
bitsParity
[
j
]
%
2
)
==
0
){
bitsParity
[
j
]
=
1
;
}
else
{
bitsParity
[
j
]
=
0
;
}
// Atribui os bits para parity (variável de paridade do objeto)
parityTest
=
(
parityTest
<<
1
)
|
bitsParity
[
j
];
}
if
(
parityTest
==
parity
){
return
1
;
}
else
{
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment