45 lines
		
	
	
		
			570 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			570 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| #include "Buffer.h"
 | |
| 
 | |
| class BitReader
 | |
| {
 | |
| public:
 | |
|   int k = 8;
 | |
|   Buffer buffer;
 | |
|   char x = 0;
 | |
|   size_t pos = 0;
 | |
| 
 | |
|   int readInt()
 | |
|   {
 | |
|     int ret = *(int *)&buffer.buffer[pos];
 | |
|     pos += 4;
 | |
|     return ret;
 | |
|   }
 | |
| 
 | |
|   unsigned short int readShort()
 | |
|   {
 | |
|     short ret = *(unsigned short int *)&buffer.buffer[pos];
 | |
|     pos += 2;
 | |
|     return ret;
 | |
|   }
 | |
| 
 | |
|   char readByte()
 | |
|   {
 | |
|     x = buffer.buffer[pos];
 | |
|     pos++;
 | |
|     return x;
 | |
|   }
 | |
| 
 | |
|   bool readBit()
 | |
|   {
 | |
|     if (k == 8)
 | |
|     {
 | |
|       readByte();
 | |
|       k = 0;
 | |
|     }
 | |
|     bool b = (x >> k) & 1;
 | |
|     k++;
 | |
|     return b;
 | |
|   }
 | |
| };
 |