I was wondering how I can save space writing a bitset to a file ( probably using iostream) in c++. Will breaking up the bitset into bitset of size 8 and then writing each individual bitset to the file save me space? What is your thought about this. This is the intention of data compression.
Save space writing bitset to a file in C++
1.7k views Asked by DogDog At
2
There are 2 answers
0
Rexxar
On
If you use boost::dynamic_bitset instead, you can specify the type of the underlying blocks and retrieve them with to_block_range and from_block_range functions.
http://www.boost.org/doc/libs/1_46_0/libs/dynamic_bitset/dynamic_bitset.html#to_block_range
(for example, use unsigned char as block type and store them in a stream in binary mode)
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in IOSTREAM
- Writing tuple data into a file using a loop
- Is it safe to output a NULL char to std::cout?
- Why is my vector not being written to code?
- C++ Input/Output stream
- No such file or directory #include <iostream>
- cin is not working in a Do..While loop, program is crashing directly after start
- Segmentation fault in c++ in visual studio code
- Can't display accents when executing a cpp code
- Undefined references to std::iostream functions?
- Printing std::u8stream in std::ostream and a concept for checking it
- #include <iostream>
- Inconsistent output order of std::cout and std::cerr in CLion
- The book "Accelerated C++: Practical Programming by Example". End-of-file indictation misunderstanding
- Stream insertion operator >> for std::optional
- How does std::setprecision affect general floating-point formatting?
Related Questions in BITSET
- Did I implement the increment operator for my dynamic bit set correctly because it is giving unexpected output
- Strange bitset output after cast from uint64_t to double and back to uint64_t
- Counting occurrence number of bits equal to 1 in two different bitsets
- How to convert large bitsets ie bitset<256> into hexadecimal in C++?
- Adding boost/dynamic_bitset using CPM Package Manager
- integer flags in system function calls
- Java BitSet.size() is not returning the size I gave at the constructor
- Dealing with a pointer to a bitset in C++
- Implementing Type SB riscv instruction in C
- Arduino SoftwareSerial wrong values
- Storing List<Integer> into Redis as a bitmap
- C++ how can I read runtime bitset parameter from file which I will use non-constexpr class
- converting from BigInt to BitArray
- Persisting BloomFilterRedis
- Efficient equality test for bitstrings with arbitrary offsets
Related Questions in COMPRESSION
- Should I compress images in java backend before sending to frontend?
- saving always adds artefacts to my images that photoshop doesn't
- Kafka compression on Broker side
- I am trying to compress video in Android using ffmpeg
- Compress gzip/Deflate string with golang
- how to convert different length of bits into byte array?
- knowledge distillation in a multistep model
- How to decompress the contents of a var to another var?
- Why response body not compressed when use webtestclient?
- How to monkey-patch np.savez_compressed to add compression level, without editing numpy's source files?
- incorrect header check while implementing GZIP in spring boot REST APIs
- Create algorhitm to create .pak file from unpack code
- Problem with decompressing algorithm in firefox (works in chrome/edge)
- Can I ignore some keyword while compressing css file through webpack? In other words I need a loader which just compress my file without validation
- PNG cropping increases file size
Related Questions in LOSSLESS-COMPRESSION
- How does a decompressor know the huffman tree that was used by the compressor?
- What is the difference between 7-zip Deflate and zlib.compress()?
- Shifting a 1 bit into high and 0 bit into low in arithmetic compression
- Questions about the frequency table in arithmetic encoding compression
- How do I set up CloudLab for a Simple Experiment?
- Compression of Database using FP trees
- Is there any way to to compress large size pdf file using only python library no external .exe
- Compute the compression ratio by using Huffman encoding
- Compute the compression ratio for Huffman algorithm
- CABAC for image compression
- How to normalize overflowed state in range asymmetric numeral systems?
- Does any compression standard uses integer DCT?
- combining two seperate numbers into a single byte and being able to uncombine them later
- Compressing multi-spectral image
- Unknown compression used in block of data, could use some fresh eyes on this
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
If you normally write one byte per bit in the bitset, then yes, storing eight elements to a byte will save you 7/8 of the space in the limit (you will have to store the size of the bitset somewhere, of course).
For example, this writes a
bitsetusing one character per bit (7/8 overhead):while this stores it optimally compact (if we disregard padding at the end):
Note that
uint8_tis not standard C++03. It resides in C99's<stdint.h>or C++0x's<cstdint>. You can also use anstd::bitset<8>if you want.