-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preenche e escreve o buffer de 1byte em "filename.txt"
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
1 parent
297c781
commit 7ec9e5f
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |