bits of all types of files(txt,mp3,gpn etc)

Dear all.
please kindly but freely provide of your ideas and thought about following.
I need to get binary bits of variety of files regardless of ASCII, Unicode, or even non-printable etc. I searched following seems to be commonly used but not for all.
 
bits[i] = ((1<<i) & c) != 0 ? 1:0;


 
bitset<8> qBits(buffer[j]);


Will you please provide any other way of getting bits of files???
This is important task for me, and any of your response will highly be appreciated.
Thanks in advance for your attention.
Sincerely
Ted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
#include <iterator>
#include <limits>
#include <bitset>
#include <vector>

int main()
{
    std::ifstream file( "file name", std::ios::binary ) ;

    typedef unsigned char byte ;
    std::istream_iterator<byte> begin(file), end ;

    typedef std::bitset< std::numeric_limits<byte>::digits > bits ;
    std::vector<bits> bytes( begin, end ) ;

    for( const bits& b : bytes ) // C++11 
    {
        static int n = 0 ;
        std::cout << b << ' ' ;
        if( ++n % 8 == 0 ) std::cout << '\n' ;
    }
}
Topic archived. No new replies allowed.