c++ - Reading any file (not .bin file) byte by byte -


i want read any file (.bin, .txt, .jpg, .zip, .mp3 etc.) byte byte (or bit bit) , display on console (in format 00100011). there questions answered in website .bin files. should not matter file format work with. example, when open .png file in text editor, see weird characters on screen "∑p®pt™5à*" , presume these every 8 bits of file turned ascii letters , displayed on editor (please correct me if wrong).

i writing program in c++ , far tried

fstream file("foo.txt", ios_base::binary);

to read file in binary mode , 8 bits of chunks, works .txt files , displays characters in text file do. not work or open other file formats .png .

can hints how can achieve this, , please correct me if gave wrong information.

you assigning values "char" datatype. should use unsigned types ("unsigned char" should suffice case) because there no negative values binary files , able read 0-255 instead of 0-127(text characters). then, if want displayed in binary, can use this:

unsigned char c = 251; char binary[8]; itoa(c, binary, 2); cout << binary << endl; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -