-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitInputStream.cpp
More file actions
62 lines (52 loc) · 1.24 KB
/
Copy pathBitInputStream.cpp
File metadata and controls
62 lines (52 loc) · 1.24 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
/*******************************************************************
*
* Kening Zhang, Gang Yang
* CSE 100, fall 17
* 11/9/2017
* cs100fje cs100fiy
*
* Assignment 3
* Filename: BitInputStream.cpp
* Description: set the fill method to read the input stream, and
* the readBit method to read the bit. Last, use the
* isEOF to check the error
******************************************************************/
#include <iostream>
#include "BitInputStream.h"
#define b_fill 8
#define move_bit 7
typedef unsigned char byte;
using namespace std;
/** read the input stream and set the counter to 0
*/
void BitInputStream::fill()
{
in.read((char*)&buffer,sizeof(char));
counter=0;
}
/** read the bit of the input stream
*/
int BitInputStream::readBit()
{
// check the buffer is filled
if (counter == b_fill)
fill();
// set the mask
byte mask=0x01;
mask=mask << (move_bit-counter);
mask = mask & buffer;
mask= mask>> (move_bit-counter);
counter++;
// check if we get 0 or 1
if (mask == 0x00)
return 0;
else if (mask == 0x01)
return 1;
}
/** return true if the stream's eofbit error state
* flag is set
*/
bool BitInputStream::isEOF()
{
return in.eof();
}