consolidate all repos to one for archive
This commit is contained in:
43
projektna_naloga/compression/include/BitWriter.h
Normal file
43
projektna_naloga/compression/include/BitWriter.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include "Buffer.h"
|
||||
|
||||
class BitWriter
|
||||
{
|
||||
public:
|
||||
int k = 0;
|
||||
Buffer buffer;
|
||||
char x = 0;
|
||||
|
||||
void writeByte(uint8_t v)
|
||||
{
|
||||
buffer.add_end(&v, sizeof(v));
|
||||
}
|
||||
|
||||
void writeInt(int v)
|
||||
{
|
||||
buffer.add_end((uint8_t *)&v, sizeof(v));
|
||||
}
|
||||
|
||||
void write16(unsigned short int v)
|
||||
{
|
||||
buffer.add_end((uint8_t *)&v, sizeof(v));
|
||||
}
|
||||
|
||||
void writeBit(bool b)
|
||||
{
|
||||
if (k == 8)
|
||||
{
|
||||
writeByte(x);
|
||||
k = 0;
|
||||
x = 0;
|
||||
}
|
||||
x ^= (-b ^ x) & (1 << k);
|
||||
k++;
|
||||
}
|
||||
|
||||
void finish()
|
||||
{
|
||||
if (k > 0)
|
||||
writeByte(x);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user