forked from ucsd-cse30-fall-2016/lab03-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.h
More file actions
72 lines (66 loc) · 2.68 KB
/
decoder.h
File metadata and controls
72 lines (66 loc) · 2.68 KB
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
/**
* DO NOT MODIFY THIS FILE. IT WILL NOT BE COLLECTED
*/
#pragma once
#include <stdbool.h>
#include <stdio.h>
/**
* Takes a char c and int index as input.
* Extracts the bit at the input index from the char c. The 0 index
* refers to the LSB, so for example, index 2 should extract the 3rd
* least significant bit.
*
* @param c the char to extract a bit from
* @param index the index of the bit to extract
* @returns the value of the bit at index in c
*/
int extractBit(char c, int index);
/**
* Takes a 6 character array as input and returns the corresponding
* char from MAPPING that is indexed by the binary ASCII string b.
* For example, if b = "010101", then the char that is mapped to it is
* in MAPPING, index 1*16 + 1*4 + 1*1 = 21.
*
* @param b a pointer to a 6 character array, with ASCII '1's and '0's
* @returns the corresponding character from MAPPING
*/
char decodeChar(char *b);
/**
* Takes a FILE handle in as input (corresponding to
* an encoded file) and reads the file, char by char. The
* bit at the input index of each char is extracted (by calling
* extractBit). The least significant bit is in index 0.
*
* For each character, if the extracted bit is 0, output ASCII '0' to
* the output file. If the extracted bit is 1, output ASCII
* '1' to the output file.
*
* @param in the input file handle to read from
* @param out the output file to write the extracted ASCII binary into
* @param index the index of the bit to extract from each char
*/
void codeToBinary(FILE *in, FILE *out, int index);
/**
* Takes a FILE handle in as input (corresponding to a
* "binary" decoded file) and reads the file, 6 chars at a
* time. Each 6 chars (all ASCII 0's and 1's) should be read into a
* char array and decoded into its corresponding char (by calling
* decodeChar). The resulting chars would be output to the FILE handle
* pointed to by out.
*
* @param in the input file, encoded as ASCII '1's and '0's
* @Param out the decoded output file (ASCII)
*/
void binaryToText(FILE *in, FILE *out);
/**
* Reads in a file from the specified input path and outputs a binary decoding to
* specified bin path and a fully decoded version to specified output path.
* This should simply open the necessary files, call the above helper functions
* in the correct sequence, and close the necessary files.
*
* @param input the path to the input file
* @param bin the path to the decoded ASCII binary output file
* @param output the path to the decoded output file
* @param index The index of the bit from which binary values should be extracted
*/
void decodeFile(char* input, char* bin, char* output, int index);