Question

Create a C++ program to add either even or odd parity, no parity as default, to...

Create a C++ program to add either even or odd parity, no parity as default, to a byte. Next randomly flip one bit and detect that there is an parity error and report. Submit source code.

Algorithm to create and add parity bit:

integer array[8]

integer even = 0, odd = 0;
integer bitcount=0;

for (intgere i=0; i <6; i++)
{
    if (array[i] == 1)
    {
        increment bitcount
    }
}

if (bitcount modulus 2 equal zero){
    even = 0
   odd = 1
}
else {
    even = 1
   odd = 0
}

if (parityType is even)
     array[7] = even
else if (parityType is odd)
   array[7] = odd

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ program: parity.cpp

================

#include <stdlib.h>
#include<stdio.h>
#include <time.h>

int main()
{
int array[8]={1,0,0,1,0,1,0,0};
int even=0;
int odd=0;
int bitcount=0;
int parityType=0;

// Algorithm to create parity
for (int i=0; i <6; i++)
{
if (array[i] == 1)
{
bitcount++;
}
}
if (bitcount%2==0){
even = 0;
odd = 1;
}
else {
even = 1;
odd = 0 ;
}
// Algorithm to add parity
if (parityType ==0)
array[7] = even;
else if (parityType==1)
array[7] = odd;

printf("Original data ");
for(int i=0; i <7; i++)
printf("%d",array[i]);

// flipping a bit randomly
printf(" Corrupted data ");
int r = rand() % 8;
array[r]=!array[r];
for(int i=0; i <7; i++)
printf("%d",array[i]);

for (int i=0; i <7; i++)
if (array[i] == 1)
bitcount++;

if (parityType ==0 && bitcount%2!=0 || parityType ==1 && bitcount%2!=1 )
printf(" Parity error detected ! ");

}

==================

Output:

Add a comment
Know the answer?
Add Answer to:
Create a C++ program to add either even or odd parity, no parity as default, to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In an even/odd parity error code a computer receives the following 4 bit word: 1101 Is...

    In an even/odd parity error code a computer receives the following 4 bit word: 1101 Is this a valid word? Why or why not? If not, can it be corrected? If yes how if not why? At least how many Bit flip must separate code words If I want to correct (not just detect) 1 bit-flip errors?

  • ****************IN C PROGRAMMING**************** Sometimes even the smallest change in data can make a big difference. Luckily,...

    ****************IN C PROGRAMMING**************** Sometimes even the smallest change in data can make a big difference. Luckily, there are algorithms that will let us not only detect when there has been an error(like checksums), but also correct when an error has occurred. These algorithms are called error-correcting codes.There are many examples of error correcting codes but one of the simplest examples is called a parity bit. A parity bit is just a single bit (1 or 0) that indicates whether a...

  • Write a program in 68K assembly code that adds an odd parity to each ASCII character....

    Write a program in 68K assembly code that adds an odd parity to each ASCII character. Your code must satisfy the following specifications: 1. Define the following 64 characters in the SRC address.SRC:DC.B 'Computing and Software Systems, University of Washington Bothell' 2. Define the 64-byte space.DST:DC.B 64 3. Read each of the 64 characters, (i.e., each byte) into D0, check the number of 1s in it, set 1 to the MSB with "ORI.B #$80, D0" to create an odd parity,...

  • 2. Design an even parity detection circuit. A parity bit is an error checking mechanism. Your...

    2. Design an even parity detection circuit. A parity bit is an error checking mechanism. Your circuit will count the number of 1's in a stream of bits. If the number of l's is even, the circuit turns on an output called y. Assume a single bit at each cycle - call the input x. Do not use an accumulator or counter. Design the even parity detection circuit using J-K flip-flops. Your answer must include: a. The state diagram. b....

  • Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data structure with...

    Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data structure with underlying linked chain; To utilize and implement code dealing with parity big codes for error detection; To read data from file **The other answer when searching for this question does not have a ParityChain class, a ParityChainDemo class or even include some of the stated requirements (such as hasError method). **Parity bit was specified by instructor to be LEFT most bit in chain In...

  • Write a program that check odd / even numbers (from number 1 to 100). Display the...

    Write a program that check odd / even numbers (from number 1 to 100). Display the results within an HTML table with 2 columns: one for odd number and one for even numbers. NUMBERS RESULTS ODD EVEN ODD 2 HINT: use <table> tags to create a table, <th> tags for 'Numbers' and 'Results'. Wrap code PHP inside HTML code. For example: <html> <title>CHECK ODD or EVEN</title> <body> <table> ?php echo "<tr><td>l</td><td>Odd</td</tr>"; </table> </body </html 2. Do the following steps in...

  • **I asked this question once, and the answer completely ignored a majority of the rules listed...

    **I asked this question once, and the answer completely ignored a majority of the rules listed on this. PLEASE read what is necessary before giving an answer. **NEITHER answer when searching for this question has a ParityChain class, a ParityChainDemo class or even include some of the stated requirements (such as hasError method). **Parity bit was specified by instructor to be LEFT most bit in chain Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data...

  • 7. Show parity using odd I's with double parity, for following data 11001101110. (10 pt.) UG 8. Show the hamming code for any 6-bit data. (10pt.) 9. What are the polynomial equivalence of fol...

    7. Show parity using odd I's with double parity, for following data 11001101110. (10 pt.) UG 8. Show the hamming code for any 6-bit data. (10pt.) 9. What are the polynomial equivalence of following bits. (10 pt.) 1100101 0011101 1110001 010100 Assume a sender has the following data frames. Suppose the sender using burst error detection/correction. Show the actual row and column that is send and received. (10pt.) 1- 0110 2- 1101 3- 0011 4- 0101 11. In terms of...

  • Can I get some help with this question for c++ if you can add some comments...

    Can I get some help with this question for c++ if you can add some comments too to help understand that will be much appreciated. Code: #include <cstdlib> #include <getopt.h> #include <iostream> #include <string> using namespace std; static long comparisons = 0; static long swaps = 0; void swap(int *a, int *b) {     // add code here } void selectionSort(int *first, int *last) {     // add code here } void insertionSort(int *first, int *last) {     // add code here }...

  • C# QUESTION Requirements Your task is to write a program that will print out all the s of the com...

    C# QUESTION Requirements Your task is to write a program that will print out all the s of the command line arguments to a program For example, given the arguments 'gaz, wx,and 'edc, your program should output wsxaazea Your implementation is expected to use Heap's algorithm according to the following pseudocode: procedure generatelk: integer, A: array of any): if k 1 then output A) else // Generate permutations with kth unaltered //Initially k length(A) // Generate permutations for kth swapped...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT