-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_output.c
39 lines (26 loc) · 961 Bytes
/
bit_output.c
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
/* BIT OUTPUT ROUTINES. */
#include <stdio.h>
#include "bit_io.h"
/* THE BIT BUFFER. */
static int buffer; /* Bits buffered for output */
static int bits_to_go; /* Number of bits free in buffer */
/* INITIALIZE FOR BIT OUTPUT. */
void start_outputing_bits(void)
{ buffer = 0; /* Buffer is empty to start */
bits_to_go= 8; /* with. */
}
/* OUTPUT A BIT. */
void output_bit(int bit)
/* int bit; */
{ buffer >>= 1; /* Put bit in top of buffer.*/
if (bit) buffer |= 0x80;
bits_to_go -= 1;
if (bits_to_go==0) { /* Output buffer if it is */
putc(buffer,fo); /* now full. */
bits_to_go = 8;
}
}
/* FLUSH OUT THE LAST BITS. */
void done_outputing_bits(void)
{ putc(buffer>>bits_to_go,fo);
}