Skip to content

Commit

Permalink
Preenche e escreve o buffer de 1byte em "filename.txt"
Browse files Browse the repository at this point in the history
Adiciona o valor bit para o caracter menos significante do buffer, faz shift e volta a adicionar o bit. Com bit=1 (constante) ficam todos os bits do buffer a 1.
  • Loading branch information
carlos54vidal authored Nov 24, 2021
1 parent 297c781 commit 7ec9e5f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ex1/testewb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <fstream>


using namespace std;


int main (){ /* Write the least significant bit of the argument */

ofstream ofs ("filename.txt");
unsigned char buffer = 0x00;
int nbits = 0;
int bytes = 2;
int nbytes = 0;
unsigned char bit = 1;
unsigned char comp = 0xFF;


while (nbytes < bytes){
int nbits = 0;
for(int i = 0; i < 8; i++){
buffer = ((buffer << 1) | bit); ///shift 1 possição e set the last bit of the buffer to bit
nbits++;
}

cout << "teste" << "buffer= "<< buffer << "nbits =" << nbits << endl;
cout << "tamanho do buffer= " << sizeof (buffer) << "bytes" << endl;

if(nbits = 8)
{
ofs << buffer;
ofs.flush();
buffer = 0;
nbytes++;
}

}
ofs.close();
return 0;
}

0 comments on commit 7ec9e5f

Please sign in to comment.