martedì 26 marzo 2013

C++: bit -> valori binari



#include <cstdio>
#include <iostream> 
#include <fstream>
#include <cstdlib>
#include <vector>

using namespace std;

int main(int argc, char *argv[]){
ifstream in(argv[1]);
ofstream out(argv[2]);


if(in.is_open()){printf("File %s trovato\n", argv[1]);}
else{printf("File %s NON trovato\n", argv[1]);}

if(out.is_open()){printf("File %s creato\n", argv[2]);}
else{printf("File %s NON creato\n", argv[2]);}

char c;
char buffer = 0;
int cont = 0;
char temp;

while(in >> c){

for(int i=0;i<8;++i){
temp =  (c >> (7-i)) & 1;
if(temp==1)
cout << 1;
else
cout << 0;
if(i==3)
cout << ".";
if(i==7)
cout << " ";
}
cout << "\n";

}




in.close();
out.close();
}

Nessun commento:

Posta un commento