Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

Count Bits in Text File Communication Protocol Worksheet

Count Bits in Text File Communication Protocol Worksheet

Description

Description

You are working with a friend on a communication protocol. The protocol is very simple: you have a 16-bit bus that sends 16-bits every clock tick. You have found problems occur if too many of the bits are set or unset.

To find out if this will create a problem you have trace files with 16-bit binary samples of the bus. You will check the number of set bits for each consecutive pair of samples in a file and output the lowest and highest percentage that you see. The percentages you output will be rounded to the nearest whole number using round() from math.h. Each sample will be encoded as a binary number that may have leading zeros.

here is an example file, sample.dat:

0000000011111111
1010101010101010
101010101010101
0000000000000000
1111111111111111

For the first pair of numbers: 0000000011111111 and 1010101010101010 has 50% set bits. The next pair 1010101010101010 and 101010101010101 has 50% set bits. The third pair 101010101010101 and 0000000000000000 has 25% set bits. The final pair 0000000000000000 and 1111111111111111 has 50% set bits. So, the program will output:

25%
50%

since 25% was the lowest number of set bits and 50% was the highest.

If you encounter any errors, you will stop, print and error with the invalid line, and exit with a code of 2.

TO COUNT THE NUMBER OF SET BITS, YOU MUST USE STRTOL TO CONVERT THE STRING TO A NUMBER AND COUNT THE BITS. DO NOT COUNT THE NUMBER OF 1 CHARACTERS.

If sample1.dat is

1
hello
101010101
110011111

running ./biased_bits with that file should look like:

$ ./biased_bits sample1.dat
invalid: hello
$ echo $?
2

Too many bits, even if it is a zero bit, is also invalid, for example, sample2.dat:

10101010
000000000000111111
1

would produce:

$ ./biased_bits sample2.dat
invalid: 000000000000111111
$ echo $?
2

If you get passed an file that you cannot open for reading, use perror to indicate the problem with the file, passing the filename as the parameter to perror, and exit with a code of 2.

$ ./biased_bits bad_file.dat
bad_file.dat: No such file or directory
$ echo $?
2

If you get a file that doesn’t have enough samples to collect a pair, print the following error and exit with a code of 2.

For example, the file short.dat:

101

would produce

$ ./biased_bits short.dat
not enough samples
$ echo $?
2

Required Functions

When implementing your solution, you must use strtol from #include <stdlib.h> to convert strings to numbers, printf from #include <stdio.h> to generate output, exit to generate an exit code, round from #include <math.h> to implement rounding, fopen to open the sample file, fclose to close it, getline to read the lines, and free to free allocated memory.

Examples


Command to RUN: ./runvalgrind.sh ./biased_bits
Expected Exit Code: 1
USAGE: ./biased_bits sample_file

Command to RUN: ./runvalgrind.sh ./biased_bits short.dat
Expected Exit Code: 2
not enough samples

Command to RUN: ./runvalgrind.sh ./biased_bits sample.dat
Expected Exit Code: 0
25%
50%

Command to RUN: ./runvalgrind.sh ./biased_bits short.dat
Expected Exit Code: 2
not enough samples

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Writers Hero only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Writers Hero are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Writers Hero is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Writers Hero, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.