Skip to content

JBx7149/bitstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Bit stream library

Introduction

This library was made to make things like decoding / encoding base64 and accessing binary files easier.

Creating a bitstream

New bitstream is created by typing

bitStream bs;
bs.open(/* desired size in bytes */);

The size is in bytes cause the bitstream uses byte arrays to save data. Bit stream can also be created from an existing byte array.

bitStream bs;
bs.openBytes(/* array pointer */, /* array size */);

After opening bitstream and working with it can be closed by doing typing

bs.close();

Closing a bitstream frees memory that was allocated to create it. If you created the bitstream by opening an array then closing the bitstream will free memory allocated for the array.

Writing to and reading from bitstream

To read from bitstream you type

bs.read(/* index (in bits) */, /* size (in bits) */);

and to write to bitstream use

bs.write(/* index (int bits) */, /* size (in bits) */, /* an integer (a value) */);

size must be smaller than 32 bits and the value is an integer. If we have the following bitstream

0 0 0 1 1 0 1 1

and we type

bs.write(0, 4, 11); // 11 = binary 1011

we will get

written value
   |
+--+--+
1 0 1 1 1 0 1 1

To turn the bitstream to a byte array type

bs.toByteArray(); // returns a char* pointer (when changes are made to the bitstream using bs.write, the returned array will also change)

About

C++ library that enables directly changing and reading bits

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages